How to remove_action inside class [duplicate]

It’s not possible to remove it with remove_action() the way you’ve written it. When you hooked it here: add_action( ‘woocommerce_shop_loop_item_title’, array( $this, ‘change_title’ ), 10 ); The $this means that the function that’s hooked is on this specific instance of My_class. When using remove_action() you need to pass the same instance of the class: remove_action( … Read more

Declaring custom woocommerce product type as virtual / downloadable only [closed]

Looking further into the WooCommerce source, they fortunately, provide a filter named woocommerce_product_data_tabs which will allow you to conditional unset tabs. I’ve provided an example below: add_filter(‘woocommerce_product_data_tabs’, function($tabs) { /** * The available tab array keys are: * * general * inventory * shipping * linked_product * attribute * variations * advanced */ unset($tabs[‘shipping’]); return … Read more

Add Additional “Checkout” button next to “Add to cart” button in woocommerce product page

You dont need to modify your template files for this, instead you can use the WooCommerce hook woocommerce_after_add_to_cart_button. This hook will add content after the “Add to cart” button. If the customer clicks on this button, the product should get added to the cart, and the customer should be send to the checkout page, right?! … Read more

WooCommerce Template overriding not working with woocommerce.php

It’s a custom theme, so first of all you should check if WooCommerce support is declared in the functions.php. WooCommerce can be integrated with the theme by using woocommerce_content() (woocommerce.php file) or by template overrides, but in both cases the declaration of support in the theme is required. function wpse319485_add_woocommerce_support() { add_theme_support( ‘woocommerce’ ); } … Read more

WooCommerce add_to_cart() with custom price [closed]

Currently there is no straight way to add custom price to product which is added through function $woocommerce->cart->add_to_cart (Documentation) but we have a bypass way that i explain in code below global $woocommerce; $custom_price = 1000; // Cart item data to send & save in order $cart_item_data = array(‘custom_price’ => $custom_price); // woocommerce function to … Read more

Add Custom CSS to Woocommerce Product Page in a specified category

Here’s my solution… Added the following to functions.php in my child theme: add_filter( ‘body_class’,’my_body_classes2′ ); function my_body_classes2( $classes ) { if ( is_product() ) { global $post; $terms = get_the_terms( $post->ID, ‘product_cat’ ); foreach ($terms as $term) { $product_cat_id = $term->term_id; $classes[] = ‘product-in-cat-‘ . $product_cat_id; } } return $classes; } Now whenever you’re viewing … Read more

How to show “Previous Category” and “Next Category” in categories archieve template [closed]

This is about PHP, not about WordPress, but here you go: get_categories returns a simple array of categories, not an indexed array. Your foreach loop tries to adress it as an indexed array. Hence the error. Also, $position becomes an undefined variable, and the loop is unnecessary anyway. $position = array_search ($this_category->term_id, $categories); $next_cat = … Read more