Set a default quantity input value for a variable product category in WooCommerce

On woocommerce_available_variation hook the $args array doesn’t include input_value argument. Also You are not using has_term() conditional function in the right way for product categories. So try the following code instead: add_filter( ‘woocommerce_available_variation’, ‘customizing_available_variation’, 10, 3 ); // Variations function customizing_available_variation( $args, $product, $variation ) { if( has_term( ‘flyer’, ‘product_cat’, $product->get_id() ) ) { $args[‘max_qty’] … Read more

Set a specific default stock quantity on all WooCommerce new products

For “New” simple products on admin, the following embedded jQuery script will: trigger and enable “Stock management” at product level, set the “Stock quantity” to “1”, set the “Low stock threshold” to “0”. The code: add_action( ‘admin_footer’, ‘new_product_stock_default_setting’ ); function new_product_stock_default_setting() { global $pagenow, $post_type; // Targeting new product page (admin) if( $pagenow === ‘post-new.php’ … Read more

Unable to programmatically remove product from WooCommerce cart

I guess you should use your function on the hook woocommerce_add_to_cart instead of template_redirect Your function works fine for me. Try an alternative methow which also works: add_action(‘template_redirect’, function () { $product_id = 29690; foreach( WC()->cart->get_cart() as $key=>$item){ if($item[‘product_id’]==$product_id){ WC()->cart->remove_cart_item( $key ); } } // $product_cart_id = WC()->cart->generate_cart_id( $product_id ); // $cart_item_key = WC()->cart->find_product_in_cart( $product_cart_id … Read more

Display a list subcategories under the main product category thumbnails?

Ok so after some more searching online and using the right combination of search terms I stumbled across this guide here: https://www.themelocation.com/how-to-display-all-the-subcategories-from-a-specific-category-in-woocommerce/ From that guide I created this snippet of code that can be added to your theme’s functions.php file so that the subcategory list appears under the main category title in the main categories … Read more

Why do Woocommerce templates use hooks rather than get_template_part

I’m not familiar with Woocommerce, but in short, get_template_part() only look for template parts in parent and child themes, not in plugins. If you look at the source code, get_template_part() uses locate_template which have the following source code (which is where the actual template part is searched for) function locate_template($template_names, $load = false, $require_once = … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)