Set cart item price from a hidden input field custom price in Woocommerce 3

Update 2021 – Handling custom price item in mini cart First for testing purpose we add a price in the hidden input field as you don’t give the code that calculate the price: // Add a hidden input field (With a value of 20 for testing purpose) add_action( ‘woocommerce_before_add_to_cart_button’, ‘custom_hidden_product_field’, 11 ); function custom_hidden_product_field() { … Read more

Allow specific products to be purchased only if a coupon is applied in Woocommerce

For defined products, the following code will not allow checkout if a coupon is not applied, displaying an error message: add_action( ‘woocommerce_check_cart_items’, ‘mandatory_coupon_for_specific_items’ ); function mandatory_coupon_for_specific_items() { $targeted_ids = array(37); // The targeted product ids (in this array) $coupon_code=”summer2″; // The required coupon code $coupon_applied = in_array( strtolower($coupon_code), WC()->cart->get_applied_coupons() ); // Loop through cart items … Read more

Multi checkbox fields in Woocommerce backend

2021 Update 2021 Update – Solved issues with: • in_array() where 2nd argument was a string on start*. • $thepostid as in some cases it was empty. That is possible creating a custom function this way: // New Multi Checkbox field for woocommerce backend function woocommerce_wp_multi_checkbox( $field ) { global $thepostid, $post; if( ! $thepostid … Read more

Replace add to cart button with a read more linked to product page on shop pages in WooCommerce 3

Replacing the button add to cart by a link to the product in Shop and archives pages for woocommerce 3+: add_filter( ‘woocommerce_loop_add_to_cart_link’, ‘replacing_add_to_cart_button’, 10, 2 ); function replacing_add_to_cart_button( $button, $product ) { $button_text = __(“View product”, “woocommerce”); $button = ‘<a class=”button” href=”‘ . $product->get_permalink() . ‘”>’ . $button_text . ‘</a>’; return $button; } Code goes … Read more

Changing WooCommerce cart item names

The woocommerce_order_item_name filter hook is a front-end hook and is located in: 1) WooCommerce templates: emails/plain/email-order-items.php templates/order/order-details-item.php templates/checkout/form-pay.php templates/emails/email-order-items.php 2)WooCommerce Core file: includes/class-wc-structured-data.php Each of them has $item_name common first argument, and different for the other arguments. See Here for more details… You have 2 arguments set in your function (the second one is not … Read more

Remove attribute values from product variation title and show them on separate rows

UPDATED 1) Since WooCommerce 3+, to remove attribute values from Product variation title and to display them in a separate row will need to use this 2 dedicated simple hooks (in checkout page). Removing attribute values from Product variation title: add_filter( ‘woocommerce_product_variation_title_include_attributes’, ‘variation_title_not_include_attributes’ ); function variation_title_not_include_attributes( $boolean ){ if ( ! is_cart() ) $boolean = … Read more

Adding multiple tabs to WooCommerce single product pages

As you are using 4 times the same hook woocommerce_product_tabs, your problem comes from the highest priority on the first one. Instead you should use it only one time, merging that 4 hooked functions in one. Here is your functional tested code, changed a little bit: add_filter( ‘woocommerce_product_tabs’, ‘woo_custom_product_tabs’ ); function woo_custom_product_tabs( $tabs ) { … Read more

Set custom shipping rates programmatically in Woocommerce 3

As this is a filter and as the data is cached, you can’t get any output with print_r(). The correct way to make it work is the following: add_filter( ‘woocommerce_package_rates’, ‘custom_shipping_costs’, 20, 2 ); function custom_shipping_costs( $rates, $package ) { // New shipping cost (can be calculated) $new_cost = 1000; $tax_rate = 0.2; foreach( $rates … Read more

Get refunded orders and refunded order items details in Woocommerce 3

To get refunded orders you could use some dedicated WC_Order methods like the following ones that have Item Id as argument: $item_qty_refunded = $order->get_qty_refunded_for_item( $item_id ); // Get the refunded amount for a line item. $item_total_refunded = $order->get_total_refunded_for_item( $item_id ); // Get the refunded amount for a line item. You can access an array WC_Order_Refund … Read more