• Hi,

    My client’s website is using Jigoshop and I need to add some conditional code to the functions.php file to show a link to a size chart only in certain category IDs just above the add to cart button. I’ve copied the code needed into my child theme’s functions.php file as seen below but for some reason the div just won’t show for these categories. I’ve tested the same code using the is_single tag and it works fine but just can’t get it working with category IDs, any help would be appreciated please?

    <?php if ( in_category( array( 50,19,18 ) ) ) {
    echo ‘<div class=”size-chart”>Hello</div>’;
    } ?>

    Many thanks,

    Jim Isles

Viewing 4 replies - 1 through 4 (of 4 total)
  • can you post the code in a greater context?
    possibly post the full functions.php?

    as it is posted, it looks ok.

    are you targeting actual categories or possibly any custom taxonomies?

    Thread Starter jesseslam

    (@jesseslam)

    Hi,

    Thanks for the reply below is the full code in the child theme functions.php file. I am targetting actual categories in the Jigoshop so would these be custom taxonomies or categories? They want a size chart to only appear in Onesie categories of which there are 3, Onesies, Men’s Onesies and Women’s Onesies here https://www.creativequirk.com/.

    <?php
    
    if (!function_exists('jigoshop_simple_add_to_cart')) {
    	function jigoshop_simple_add_to_cart() {
    
    		global $_product; $availability = $_product->get_availability();
    
    		// do not show "add to cart" button if product's price isn't announced
    		if( $_product->get_price() === '') return;
    
    		?>
    		<form action="<?php echo esc_url( $_product->add_to_cart_url() ); ?>" class="cart" method="post">
    			<?php do_action('jigoshop_before_add_to_cart_form_button'); ?>
    <?php if ( in_category( array( 50,19,18 ) ) ) {
    	echo '<div class="size-chart">Hello</div>';
    } ?>
    <div class="quantity"><input name="quantity" value="1" size="4" title="Qty" class="input-text qty text" maxlength="12" /></div>
    		 	<button type="submit" class="button-alt"><?php _e('Add to cart', 'jigoshop'); ?></button>
    		 	<?php do_action('jigoshop_add_to_cart_form'); ?>
    </form>
    		<?php
    	}
    }
    ?>
    Moderator bcworkz

    (@bcworkz)

    If you use actual categories for product organization, then using in_category() is correct. I think alchymyth was thinking some ecommerce plugins use custom taxonomies for this purpose. If that were the case here, then in_category() would not do what you need it to.

    Your code still looks OK if jigoshop_simple_add_to_cart() is called from inside a proper WP loop that makes a call to the_post(). My guess is this is not the case, so you would need to pass the post ID to in_category() somehow. The object in $_product looks like a potential source for the ID, but I don’t know enough of jigoshop to say one way or another.

    Thread Starter jesseslam

    (@jesseslam)

    Thanks for your reply. I’m by no means an expert coder so I’l put a post on the Jigoshop forum and see if they can help.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Using conditional tags in a child theme functions.php file’ is closed to new replies.