Hide fields in checkout based on specific products

To remove a custom field from checkout in WooCommerce when a specific product is in the cart, you can use the woocommerce_checkout_fields function and remove the field based on the product. Here is a sample code that can help you: add_filter( 'woocommerce_checkout_fields', 'remove_custom_field_based_on_product' ); function remove_custom_field_based_on_product( $fields ) { // Insert the product ID here that the […]

Read More

Hide certain payment methods in the checkout for certain products

In this example, you need to customize the hide_payment_method_for_specific_products function by changing the product IDs and the names of the payment methods you want to hide according to your requirements. Add this function to your theme's functions.php and it will hide the selected payment methods based on the product IDs. Please note that this is just an example and you […]

Read More

Activate free shipping for regular customers

add_filter('woocommerce_shipping_free_shipping_threshold', 'free_shipping_for_returning_customers'); function free_shipping_for_returning_customers($threshold) { if (is_user_logged_in() && current_user_can('customer_group')) { $threshold = 0; // Free shipping for regular customers } return $threshold; }  

Read More

Create custom tabs on the product page

add_filter(&#039;woocommerce_product_tabs&#039;, &#039;custom_product_tabs&#039;); function custom_product_tabs($tabs) { $tabs[&#039;custom_tab&#039;] = array( &#039;title&#039; =&gt; __(&#039;Additional Information&#039;, &#039;woocommerce&#039;), &#039;priority&#039; =&gt; 50, &#039;callback&#039; =&gt; &#039;custom_product_tab_content&#039; ); return $tabs; } function custom_product_tab_content() { echo &#039;<h2>Additional Information</h2>&#039;; echo &#039;<p>Here you can find more information about this product.</p>&#039;; }  

Read More

Shipping costs vary depending on the number of items

add_filter('woocommerce_package_rates', 'adjust_shipping_based_on_item_count', 10, 2); function adjust_shipping_based_on_item_count($rates, $package) { $item_count = WC()->cart->get_cart_contents_count(); if ($item_count > 5) { foreach ($rates as $rate_id => $rate) { $rates[$rate_id]->cost += 2.00; // Additional shipping costs for 6 items or more } } return $rates; }  

Read More

Discount for products in the “Sale” category

add_filter('woocommerce_product_get_price', 'discount_sale_category_products', 10, 2); function discount_sale_category_products($price, $product) { $sale_category = 'sale'; // Name of the sale category if (has_term($sale_category, 'product_cat', $product->get_id())) { $price = $price * 0.8; // 20% discount for products in the sale category } return $price; }  

Read More

Custom message for sold out products

add_filter('woocommerce_get_availability', 'custom_out_of_stock_message', 1, 2); function custom_out_of_stock_message($availability, $product) { if (!$product->is_in_stock()) { $availability['availability'] = __('Unfortunately sold out - Please contact us for more information.', 'woocommerce'); } return $availability; }  

Read More

Add custom text field to checkout form

add_action(&#039;woocommerce_after_checkout_billing_form&#039;, &#039;custom_checkout_form_field&#039;); function custom_checkout_form_field($checkout) { echo &#039;<div id="”custom_checkout_field”"><h2>&#039; . __(&#039;Additional Information&#039;) . &#039;</h2>&#039;; woocommerce_form_field(&#039;custom_field&#039;, array( &#039;type&#039; =&gt; &#039;text&#039;, &#039;class&#039; =&gt; array(&#039;form-row-wide&#039;), &#039;label&#039; =&gt; __(&#039;Custom Field&#039;), &#039;placeholder&#039; =&gt; __(&#039;Enter your information here.&#039;), &#039;required&#039; =&gt; false, ), $checkout-&gt;get_value(&#039;custom_field&#039;)); echo &#039;</div>&#039;; }  

Read More