web-dev-qa-db-fra.com

Ajout de mon propre "bouton Ajouter au panier"

J'utilise Jigoshop pour créer un site de commerce électronique.

L’objectif final est que la page de couverture comprenne une section consacrée aux produits .

Jigoshop fournit un shortcode, mais le shortcode utilise par défaut une taille d'image moyenne. J'aimerais utiliser la grande taille de l'image. J'ai donc effectué WP_query de manière conditionnelle pour rechercher les images en vedette. J'ai saisi l'image, le titre et la description du produit, mais je n'arrive pas à comprendre comment obtenir le bouton "ajouter au panier". généré.

Des idées?

1
Squadrons

D'accord, j'ai réussi à le comprendre (après beaucoup trop d'heures ...):

Voici le code, n'hésitez pas à me faire savoir si c'est moche, car je connais à la fois WordPress et PHP:

//Query the wordpress database for product posts
  $my_products = new WP_Query( 
        array(
        'post_type' => 'product',
          )
        );
//loop through my queried posts
<?php while ($my_products->have_posts()) : $my_products->the_post(); $_product = &new jigoshop_product( $post->ID );?>     
//find the posts that have the meta_key 'featured' with the value of 'yes' (they all have a featured tag with either yes or no)
        <?php if(get_post_meta($post->ID, 'featured', yes) == 'yes') : ?>
//make the product header a link to the product page
        <h1><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h1>

//copied this code for getting the product thumbs                 
        <?php echo '<div class="images">';

            $thumb_id = 0;
            if (has_post_thumbnail()) :
                $thumb_id = get_post_thumbnail_id();
                // since there are now user settings for sizes, shouldn't need filters -JAP-
                //$large_thumbnail_size = apply_filters('single_product_large_thumbnail_size', 'shop_large');
                $large_thumbnail_size = jigoshop_get_image_size( 'shop_large' );
//had to edit the href from original value to .get_permalink so it would link to product page instead of the image itself
                echo '<a href="'.get_permalink().'" rel="thumbnails">';
                the_post_thumbnail($large_thumbnail_size);
                echo '</a>';
            else :
                echo jigoshop_get_image_placeholder( 'shop_large' );
            endif;
//commented out this section so it wouldn't thumbnail ALL the products images, just one
            //do_action('jigoshop_product_thumbnails');

            echo '</div>'; ?>

//get the product description        
        <p><?php the_content(); ?></p>

//create the 'add to cart' button
        <a href="<?php echo $_product->add_to_cart_url(); ?>" class="button"><?php _e('Add to cart', 'jigoshop'); ?></a> 

//reset the query (no idea if this is necessary, anyone?
    <?php wp_reset_query(); ?>
<?php endif; ?>
 <?php endwhile; ?>         
2
Squadrons