The topic ‘0.2.4 adds code to above products that meet the condition’
-
Am leaving this in case it helps someone else. I suspect something in WP or Woo changed making the links in replacements in the “Add To Cart” button stop working.
After one of the updates 0.2.3 or 0.2.4 I was also having the issue where code is being displayed above products that meet the conditions:
'; var btn_selectors = [".add_to_cart_button[data-product_id=\"235638\"]",".single_add_to_cart_button[value=\"235638\"]","form.cart[data-product_id=\"235638\"] .single_add_to_cart_button","#product-235638 form.cart .single_add_to_cart_button",".product.post-235638 form.cart .single_add_to_cart_button","a[class*=\"product_type_\"][data-product_id=\"235638\"]",".storefront-sticky-add-to-cart__content-button",".product.post-235638 form.cart","#product-235638 form.cart","form.cart[data-product_id=\"235638\"]"]; for ( var i = 0; i < btn_selectors.length; i++ ) { var _element = document.querySelector( btn_selectors[ i ] ); if ( _element ) { // if jquery is defined if ( typeof jQuery !== 'undefined' ) { jQuery( _element ).replaceWith( html ); } else { _element.outerHTML = html; } } } document.getElementById( '__235638-css' ).remove(); } );
I realized it would only happen when I added a link in the “Replace with…” under the “If condition met” selector, so I switched it “Hide Add to Cart” and added this in functions to achieve the same:
add_filter( 'woocommerce_get_price_html', 'react2wp_woocommerce_hide_product_price', 90, 2); function react2wp_woocommerce_hide_product_price( $price, $product ) { if ( ( is_product_category() ) && has_term( 'YourProductCategory', product_cat', $product->get_id() ) ) { $price = '<p><a href="https://www.YourDomain.com.sv/YourPathYouWantToShowInsteadOfPrice">YourLink </a></p>'; return $price; } else { $price = "$ ". $product->get_price(); return $price; }
Thanks Nabil, for making this available!
- The topic ‘The topic ‘0.2.4 adds code to above products that meet the condition’’ is closed to new replies.