Accessing parameters when adding filter

When you call add_filter(), set the fourth parameter to 3 (which is the number of parameters accepted by the callback function which in your case is change_rating_output()), and then change your change_rating_output() function so that it accepts the $rating and $count parameters: add_filter(‘woocommerce_product_get_rating_html’, ‘change_rating_output’, 10, 3); function change_rating_output($html, $rating, $count){ // Now do what you … Read more

Move WooCommerce product tabs out of the tabs [closed]

It turned out that woocommerce_get_template() was deprecated and replaced by wc_get_template(). I solved this by adding this to my functions.php. add_action( ‘woocommerce_after_single_product_summary’, ‘removing_product_tabs’, 2 ); function removing_product_tabs(){ remove_action(‘woocommerce_after_single_product_summary’,’woocommerce_output_product_data_tabs’, 10 ); add_action(‘woocommerce_after_single_product_summary’,’get_product_tab_templates_displayed’, 10 ); } function get_product_tab_templates_displayed() { wc_get_template( ‘single-product/tabs/description.php’ ); wc_get_template( ‘single-product/tabs/additional-information.php’ ); comments_template(); }

Woocommerce add_to_cart non-register visitor not working

I did two tests on my dev site add_action( “wp_loaded”, function() { var_dump(WC()->cart->add_to_cart(1353)); }); and add_action( “wp_footer”, function() { var_dump(WC()->cart->add_to_cart(1353)); }); Both var_dump a hash, but only the first one actually adds a product to the cart, the second prints the hash but does not add anything. What is happening is that in the second … Read more

Move add to cart in Woocommerce

You can change the priority/order by removing and re-adding the parts you want the position changed – like this: remove_action( ‘woocommerce_after_shop_loop_item’, ‘woocommerce_template_loop_add_to_cart’, 10 ); add_action( ‘woocommerce_after_shop_loop_item_title’, ‘woocommerce_template_loop_add_to_cart’, 10 ); Drop this piece of code into your functions.php to take effect.

Save and display selected product option and cost as cart item data in WooCommerce

The following revisited code will change cart item subtotal to the calculated sum of product + color option and will reflect this change to cart totals. It will save the option as order item meta data, when order is placed. The code: // Display Select field before add to cart button add_action( ‘woocommerce_before_add_to_cart_button’, ‘colors_options_before_add_to_cart_button’ ); … Read more

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