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

pre_get_posts with WooCommerce Shortcode Query

You could use the WooCommerce filter woocommerce_shortcode_products_query to change/manipulate the query arguments. This example comes from the shortcode documentation. When using the Products shortcode, you can choose to order products by the pre-defined values above. You can also sort products by custom meta fields using the code below (in this example we order product by … Read more

Hide Add to Cart Button

Just add the following code in your functions.php and you will find button hidden I don’t know whether my solution is perfect. But it works. Normally if is_purchasable is returned to the filter woocommerce_is_purchasable, the ‘Add to Cart’ button is displayed, and if false is returned the button is hidden. So, you just need to … Read more

Shortcode with product catgory counter

Try this: (add it to the theme’s main functions.php file) add_shortcode( ‘products-counter’, ‘products_counter’ ); function products_counter( $atts ) { $atts = shortcode_atts( [ ‘category’ => ”, ], $atts ); $taxonomy = ‘product_cat’; if ( is_numeric( $atts[‘category’] ) ) { $cat = get_term( $atts[‘category’], $taxonomy ); } else { $cat = get_term_by( ‘slug’, $atts[‘category’], $taxonomy ); … Read more