GET a coupon code via URL and apply it in WooCommerce Checkout page [closed]

Update 3: This can be done in a very simple way with the following 2 hooked functions: The first one will catch the coupon code in the Url and will set it in WC_Sessions. The second one will apply the coupon code from session in checkout page. Here is this code: add_action(‘init’, ‘get_custom_coupon_code_to_session’); function get_custom_coupon_code_to_session(){ … Read more

Change WooCommerce default password security level

The only existing hook setting for that is woocommerce_min_password_strength filter hook. So you can set a custom hook function and lowering this strenght. There is 4 possible settings: 3 => Strong (default) 2 => Medium 1 => Weak 0 => Very Weak (anything). Here is that code: add_filter( ‘woocommerce_min_password_strength’, ‘reduce_min_strength_password_requirement’ ); function reduce_min_strength_password_requirement( $strength ) … Read more

Woocommerce get variation product price

Here is the code you are looking for add_filter( ‘woocommerce_variation_option_name’, ‘display_price_in_variation_option_name’ ); function display_price_in_variation_option_name( $term ) { global $wpdb, $product; if ( empty( $term ) ) return $term; if ( empty( $product->id ) ) return $term; $id = $product->get_id(); $result = $wpdb->get_col( “SELECT slug FROM {$wpdb->prefix}terms WHERE name=”$term”” ); $term_slug = ( !empty( $result ) … Read more

WooCommerce: Finding the products in database

Update 2020 Products are located mainly in the following tables: wp_posts table with post_type like product (or product_variation), wp_postmeta table with post_id as relational index (the product ID). wp_wc_product_meta_lookup table with product_id as relational index (the post ID) | Allow fast queries on specific product data (since WooCommerce 3.7) wp_wc_order_product_lookuptable with product_id as relational index … Read more

Get orders total purchases amount for the day in Woocommerce

The best and effective way to get that is to use the following very light SQL query, that will get the sum of all order totals in the last 24 hours for “processing” and “completed” orders statuses: function get_daily_purchases_total(){ global $wpdb; return $wpdb->get_var( ” SELECT SUM(pm.meta_value) FROM {$wpdb->prefix}posts as p INNER JOIN {$wpdb->prefix}postmeta as pm … Read more

Add a line break in Woocommerce Product Titles

2020 revision – Still works on WordPress 5.5.1 with WooCommerce 4.4.1 Using this custom function hooked in the_title filter hook will do the job (replacing a pipe character | by a <br> in product titles): add_filter( ‘the_title’, ‘custom_product_title’, 10, 2 ); function custom_product_title( $title, $post_id ){ $post_type = get_post_field( ‘post_type’, $post_id, true ); if( in_array( … Read more

Applied coupons disable Free shipping conditionally in Woocommerce

The below code will enable “Free shipping” for applied coupons only if cart subtotal reaches a minimal amount (discounted including taxes): add_filter( ‘woocommerce_package_rates’, ‘coupons_removes_free_shipping’, 10, 2 ); function coupons_removes_free_shipping( $rates, $package ){ if ( is_admin() && ! defined( ‘DOING_AJAX’ ) ) return $rates; $min_subtotal = 250; // Minimal subtotal allowing free shipping // Get needed … Read more

Show hide custom Woocommerce checkout field based on selected payment method

The following code will hide billing_options custom optional checkout field when the selected payment method is Cash on delivery (“cod”): // Conditional Show hide checkout fields based on chosen payment methods add_action( ‘wp_footer’, ‘conditionally_show_hide_billing_custom_field’ ); function conditionally_show_hide_billing_custom_field(){ // Only on checkout page if ( is_checkout() && ! is_wc_endpoint_url() ) : ?> <script> jQuery(function($){ var a=”input[name=”payment_method”]”, … Read more

Set quantity minimum, maximum and step at product level in Woocommerce

Updated December 2020 The following revisited code will allow in addition to handle quantity steps. I have changed quantity fields settings location to “General” settings tab. I have added a checkbox that enables or disables those additional quantity settings at product level (showing or hiding the setting fields dynamically): When checkbox unchecked (fields are not … Read more