2

WooCommerce uses the template_include filter/hook to load main templates like archive-product.php and single-product.php. And here's the class which handles main templates. And there's a filter in that class which you can use to capture the default file (name) which WooCommerce loads based on the current request/page — e.g. single-product.php for ...


2

To get only available "In stock" displayed sizes, you need something a little more complicated and different: add_action( 'woocommerce_after_shop_loop_item_title', 'display_instock_sizes', 5 ); function display_instock_sizes() { global $product; if ( $product->is_type('variable') ) { $taxonomy = 'pa_size'; // The product attribute ...


1

If you want to use that function everywhere, you need to be sure that: $current_user is always defined as a WP_User object, $current_user->ID is different from 0 (zero) - only for logged in users, jQuery select2() function (plugin) exist, avoiding JS errors on some other pages (where Select 2 is not enabled). See: How can I check if a jQuery plugin is ...


1

There are some errors as get_post_meta() first argument need to be a defined product ID here (and in your code post_ID is not even dynamic variable and will not give anything)… Try the following: <?php function check_gtin(){ if ( $gtin = get_post_meta(get_the_id(), 'gtin', true) ){ echo "gtin13:". $gtin; } else { ...


1

Maybe you want to try adding products to subcategory, but not showing them on main categories. Then when user filters and goes to subc, you show products. Link


1

No idea why, but for the second snippet, changing the priority of the nested add_action from the default (10) to 20, causing the parent and child add_action to have a different priority solved the problem and now everything works perfectly: add_action( 'template_redirect', function() use ( $args ) { acau_enqueue_script ( $args ); }, 20); The reason ...


1

Actaully using esc_html won't help because it will escape any html character, so you have to depend on wp_kses so you can specify the accepted tags and there attributes, so no need then to escape the output. but you have to escape the values comming from DB, which in you case $average_rating. so your can be like this. $accepted_tags = array('strong'=>...


1

I would try duplicating this site to a staging area. Then go through and deactivate all of your plugins except for Woo Commerce. With everything disabled except Woo Commerce and your theme, try and add items to your cart. See if there is a delay for things when you add them to the cart. If there is no delay, slowly activate your plugins one at a time ...


1

Your code is outdated since WooCommerce 3. First, you need to target variable products type only to avoid errors on other products types and also $product is already the product object. Also you can also directly use the WC_Product method get_attribute() and your code will be much more simpler, compact and efficient: add_action( '...


1

Regarding the filter, you tried, not working, my hunch is that it' not working, because it's missing (priority and) accepted arg count parameter(s). At the moment add_filter('woocommerce_product_get_price', 'test_change'); Defaults to priority 10 and 1 parameter for your callback, but you're using two args in function test_change($value, $prop) { return ...


1

To account for variations, I'd suggest using $product->get_category_ids() and checking if your category is in there: function wcs_custom_get_availability( $availability, $_product ) { $workshops_category = get_term_by( 'slug', 'workshops', 'product_cat' ); $product_category_ids = $_product->get_category_ids(); if ( ! in_array( $...


1

I figured out that this happened because the attributes did not exist in WooCommerce yet. First you have to add all attributes and their values, then generate and add variations. Then it should work: // Create an array of the attributes we want to add $attributes = array( "attribute_1" => array( "slug" => "attribute_1", "label" =&...


Only top voted, non community-wiki answers of a minimum length are eligible