Enjoy unlimited access to all forum features for FREE! Optional upgrade available for extra perks.

Woocommerce issue

what PHP version are you using, Ben?
 
OK, cool.

The code snippet that appears in your opening post, is that literally copy and pasted? As there is currently a syntax issue with it if that is the case?
 
OK, cool.

The code snippet that appears in your opening post, is that literally copy and pasted? As there is currently a syntax issue with it if that is the case?

I updated it earlier as I noticed an issue. I'm not sure whether you're seeing the revised version so this is the code:

Code:
add_action( 'woocommerce_before_main_content', 'remove_test_category_thumbnails', 10 );

function remove_test_category_thumbnails() {
    if (is_product_category('test-category')) {
        remove_action('woocommerce_before_shop_loop_item_title' , 'woocommerce_template_loop_product_thumbnail' , 10);
    }
}

add_action( 'woocommerce_before_shop_loop_item_title', 'add_test_category_thumbnails', 10 );

function add_test_category_thumbnails() {
    global $post;
    $testCatThumb = get_post_meta( $post->ID, 'step_dad_mug', true);
    if (is_product_category('test-category') && (isset($testCatThumb)) ) {
        echo wp_get_attachment_image( $testCatThumb );
    }
    else
        echo woocommerce_get_product_thumbnail();
    }
}
 
The following function expects a post id. is that what you are passing it?
Code:
wp_get_attachment_image();

as part of your if condition, you could check:
Code:
is_numeric($testCatThumb);

I tend to create readable variables, rather than having horrible conditions you have to parse with your brain every time you read it:

Code:
function add_test_category_thumbnails() {
    global $post;

    $testCatThumb = get_post_meta( $post->ID, 'step_dad_mug', true);
    $isPostId = !empty($testCatThumb) && is_numeric($testCatThumb);
    $isValidAttachmentId = is_product_category('test-category') && $isPostId;

    $image = $isValidAttachmentId ? wp_get_attachment_image($testCatThumb) : '';

    echo !empty($image) ? $image : woocommerce_get_product_thumbnail();
}
 
That seems to have worked, thank you very much for your help.
 

The Rule #1

Do not insult any other member. Be polite and do business. Thank you!

Featured Services

Sedo - it.com Premiums

IT.com

Premium Members

AucDom
UKBackorder
Be a Squirrel
Acorn Domains Merch
MariaBuy Marketplace

New Threads

Domain Forum Friends

Other domain-related communities we can recommend.

Our Mods' Businesses

Perfect
Service
Laskos
*the exceptional businesses of our esteemed moderators
Top Bottom