wordpress shortcode not working

Point-1: it’s not clear where you are getting $order_id from. I’m assuming it’s in the Shortcode. Point-2: You don’t need to. use ob_* functions for returning Shortcode replacement content, simply returning is enough. Assuming other parts of your CODE is correct, below is the possible CODE that should work: If the shortcode is implemented in … Read more

How to access page variable inside action hook

There is method on product class that is called is_on_sale() which actually determines if the product is on sale or not. You can access it from global $product variable. And must echo the do_shortcode. So the whole code will be like- add_action(‘woocommerce_single_product_summary’,’add_product_signup’, 10, 2); function add_product_signup() { global $product; if( $product->is_on_sale() ) { echo do_shortcode(‘[contact-form-7 … Read more

Have Woocommerce show product price if id, when not logged in

If you know the id, you can simply check current product id in your woocommerce_get_price_html action: add_action(‘after_setup_theme’,’activate_filter’) ; function activate_filter() { add_filter(‘woocommerce_get_price_html’, ‘show_price_logged’); } function show_price_logged($price) { global $product; // get current product if(is_user_logged_in() || $product->id === 8) { // check product id return $price; } else { remove_action( ‘woocommerce_after_shop_loop_item’, ‘woocommerce_template_loop_add_to_cart’ ); remove_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_price’, … Read more

Woocommerce Remove Tax by Product Type

After many headaches and trials and errors, instead of trying to recalculate the taxes, I just altered the taxes. I changed my foreach loop in the second function to the following: if(‘metal’===get_post_meta($item[‘product_id’], ‘_product_type’, 1)): $cart->taxes[1] -= $item[‘line_tax’]; $cart->tax_total -= $item[‘line_tax’]; $item[‘line_tax’] = 0; $item[‘line_subtotal_tax’] = 0; $item[‘line_tax_data’] = []; $cart->cart_contents[$key] = $item; endif; Now it … Read more

Alter Woocommerce product archive structure

I think the subcategory thing get generated with this function woocommerce_product_subcategories();. But as you said for this layout there is no specific template file. Also, if I remember right, you cannot do this with css alone. A little while ago I created a little plugin for a customer who also wanted a product overview structured … Read more

WooCommerce coupon hook argument NULL when using filter woocommerce_get_shop_coupon_data

You need to tell add_filter how many arguments it accepts (2) example: add_filter(‘woocommerce_get_shop_coupon_data’, array( $this, ‘filter_woocommerce_get_shop_coupon_data’ ), 10, 2 ); Be sure to enable WP_Debug – http://wpexplorer-themes.com/total/docs/enabling-wp-debug/ – on your server, because you should have gotten an error when trying to do this without the added argument. Also I highly recommend using static classes when … Read more

Display data when category is empty

You have used woocommerce_after_shop_loop action hook which is within the following condition: <?php if ( have_posts() ) : ?> You should use woocommerce_after_main_content in order to display your data. Because it is outside of this condition. Your data will display even there are no products in the category. UPDATE: You can add condition to your … Read more

Custom tax_query filter not working for Woocommerce product categories

I figured out what the issue was. The page was displaying categories/subcategories and not the items themselves. This meant that woocommerce_product_subcategories() was the one filtering and that uses a different hook. Here is what I added to my functions.php file. add_filter( ‘get_terms’, ‘get_subcategory_terms’, 10, 3 ); function get_subcategory_terms( $terms, $taxonomies, $args ) { $new_terms = … Read more