Catalog mode on product conflict
-
Today I enabled a product on catalog mode
And the pages where this product was shown , the price of all products wasn’t shownI investigated the issue and the problem could be on wc-frontend-manager\core\class-wcfm-catalog.php
Line 116:
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );This line remove all the prices on the all loop, not only in the product
-
I changed the if (line 111) from:
if( $product_id ) { $is_catalog = ( get_post_meta( $product_id, '_catalog', true) == 'yes' ) ? 'yes' : ''; if( $is_catalog == 'yes' ) { $disable_price = ( get_post_meta( $product_id, 'disable_price', true) ) ? get_post_meta( $product_id, 'disable_price', true) : 'no'; if( $disable_price == 'yes' ) { remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 ); } } }To:
if( $product_id && get_post_meta( $product_id, '_catalog', true) == 'yes' && get_post_meta( $product_id, 'disable_price', true) ) remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 ); else add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 11 );Another bug
changed conditionget_post_meta( $product_id, 'disable_price', true)toget_post_meta( $product_id, 'disable_price', true) == 'yes'HI,
Thanks for improvement suggestion, we are looking into this.
Thank You
I update to 5.4.7 fixs that?
NO, our team still debugging this. It will be part of next update!
I’m waiting
Bug with my code: sometimes the hook was double, so I solved:
if( $product_id && get_post_meta( $product_id, '_catalog', true) == 'yes' && get_post_meta( $product_id, 'disable_price', true) == 'yes' ) remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 ); else if(!has_action('woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price')) add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 11 );Thanks.
this isn’t resolved, you need update your files
i detected a new update, but the problem persistNew version and the bug still unfixed
Hi,
Sorry, it’s our fault. We had mark this resolved after implemented this in core but missed to notify you.
Well, this fix is part of latest WCFM update, 6.0.3
Please update yours and take a look.
Thank You
I updated, the issue isn’t fixed. I checked your code and is wrong:
if( $product_id ) { $is_catalog = ( get_post_meta( $product_id, '_catalog', true) == 'yes' ) ? 'yes' : ''; if( $is_catalog == 'yes' ) { $disable_price = ( get_post_meta( $product_id, 'disable_price', true) ) ? get_post_meta( $product_id, 'disable_price', true) : 'no'; if( $disable_price == 'yes' ) { remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 ); } elseif( !has_action('woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price') ) { add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 ); } } }The added/removed actions performs beyond the current product impression. When you modify the actions, you are modify the “routine actions” of the all loop.
Example:
Our loop has 3 products:
1- Price disabled: true
Then you remove de action
2- Price disabled: false
The action still removed
3- Price disabled: false
The action still removedThe logic of your code isn’t considering this fact
My last proposal solution:
if( $product_id && get_post_meta( $product_id, '_catalog', true) == 'yes' && get_post_meta( $product_id, 'disable_price', true) == 'yes' ) { if(has_action('woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price') ) remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 ); } else if(!has_action('woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price') ) add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );HI,
The added/removed actions performs beyond the current product impression. When you modify the actions, you are modify the “routine actions” of the all loop.
– Then what this condition is for?
$disable_price = ( get_post_meta( $product_id, ‘disable_price’, true) ) ? get_post_meta( $product_id, ‘disable_price’, true) : ‘no’;
if( $disable_price == ‘yes’ ) {These conditions belongs to each product on the loop, because not all products can have the same option value
The topic ‘Catalog mode on product conflict’ is closed to new replies.