woocommerce_before_calculate_totals in woocommerce 3.0

Well, the problem is you are calling price directly at $value[‘data’]->price. Make it $value[‘data’]->get_price() and I think you problem will be fixed. So the whole code block will be- function calculate_embossing_fee( $cart_object ) { if( !WC()->session->__isset( “reload_checkout” )) { /* Gift wrap price */ $additionalPrice = 5; foreach ( $cart_object->cart_contents as $key => $value ) … Read more

Woocommerce – How to add 5 stars to all products to test design

@Nikola‘s answer gives you what you want to need without saving anything to the database. If you need to save the values to the database and directly execute SQL, you can do the following. Basically WooCommerce stores product reviews data as a postmeta under meta keys _wc_rating_count _wc_average_rating _wc_review_count UPDATE fs_postmeta SET meta_value = 5 … Read more

How to hook on a WooCommerce checkout field?

There is no hook woocommerce_form_field, there is hook woocommerce_form_field_{$args[type]} (doc). $args[type] can be (look here for available options): text, checkbox, country, … Code below will wrap ‘billing_first_name‘ and ‘billing_last_name‘ fields in a wrapper like <div class=”first-and-second-field-wrapper”> […] </div>. function change_woocommerce_field_markup($field, $key, $args, $value) { $field = ‘<div class=”single-field-wrapper”>’.$field.'</div>’; if($key === ‘billing_first_name’) $field = ‘<div class=”first-and-second-field-wrapper”>’.$field; … Read more

Woocommerce: show default variation price is products list?

Try this code: add_filter(‘woocommerce_variable_price_html’, ‘custom_variation_price’, 10, 2); function custom_variation_price( $price, $product ) { $available_variations = $product->get_available_variations(); $selectedPrice=””; $dump = ”; foreach ( $available_variations as $variation ) { // $dump = $dump . ‘<pre>’ . var_export($variation[‘attributes’], true) . ‘</pre>’; $isDefVariation=false; foreach($product->get_default_attributes() as $key=>$val){ // $dump = $dump . ‘<pre>’ . var_export($key, true) . ‘</pre>’; // $dump … Read more

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