How to set default values in Woocommerce checkout? [closed]

Try this code to change the default billing country on the checkout page. add_filter( ‘default_checkout_billing_country’, ‘change_default_checkout_country’ ); function change_default_checkout_country() { return ‘US’; // country code } To change default shipping country on the checkout page function change_set_checkout_field_input_value_default($fields) { $fields[‘shipping’][‘shipping_country’][‘default’] = ‘Australia’; return $fields; } add_filter( ‘woocommerce_checkout_fields’, ‘change_set_checkout_field_input_value_default’ );

How do I get the latest note on the order at woocommerce? [closed]

The order notes are saved as post comments, so you can use the WordPress function get_comments() to get the last note: $args = array( ‘post_id’ => $order_id, ‘orderby’ => ‘comment_ID’, ‘order’ => ‘DESC’, ‘approve’ => ‘approve’, ‘type’ => ‘order_note’, ‘number’ => 1 ); remove_filter( ‘comments_clauses’, array( ‘WC_Comments’, ‘exclude_order_comments’ ), 10, 1 ); $notes = get_comments( … Read more

Redirect the single product page link to the shop page

You can try using template_redirect action hook to check if the current page is product page and after that, you can redirect the user to your shop page. Paste this code into your functions.php add_action(‘template_redirect’,’custom_shop_page_redirect’); function custom_shop_page_redirect(){ if (class_exists(‘WooCommerce’)){ if(is_product()){ wp_redirect(home_url(‘/shop/’)); exit(); } } return; } I have not tested it, but hope it will … Read more

echo product id and product_item_key in cart [closed]

Techno Deviser, probably by mistake, in the foreach loop set value to $fragments[‘div.header-cart-count’] instead append it. Try this modification: function iconic_cart_count_fragments( $fragments ) { foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { $fragments[‘div.header-cart-count’] .= ‘<div class=”header-cart-count”>’ .$cart_item_key.'<br><br>’. $cart_item[‘product_id’]. ‘</div>’; } return $fragments; } Or: function iconic_cart_count_fragments( $fragments ) { $cart = WC()->cart->get_cart(); if (!empty($cart)) … Read more

Does the woocommerce_order_status_changed hook fire when WooCommerce updates an order status automatically? [closed]

One of the results did bring up this (in reference to woocommerce_order_status_changed): “Where the hook is used (in WC core): Does not used.” Which seems to answer Question 1, which is what leads me to believe if WooCommerce or a payment gateway changes the order status automatically, it will never fire, thus not creating our … Read more

WooCommerce: Email Notifications

You may be using the wrong hook. I use this : add_action( “woocommerce_email_after_order_table”, “custom_woocommerce_email_after_order_table”, 10, 1); function custom_woocommerce_email_after_order_table( $order ) { echo ‘<p>content after email table</p>’; } now, if you look at this link it will show you other hooks that you can use if you want to append other information to the email. for … Read more