orders

Set WooCommerce order status when order is created from processing to pending

青春壹個敷衍的年華 提交于 2019-12-18 06:51:40
问题 When a woocommerce order is created the status of the order is "processing". I need to change the default order-status to "pending". How can I achieve this? 回答1: The default order status is set by the payment method or the payment gateway. You could try to use this custom hooked function, but it will not work (as this hook is fired before payment methods and payment gateways) : add_action( 'woocommerce_checkout_order_processed', 'changing_order_status_before_payment', 10, 3 ); function

Set product custom field and display value in cart, checkout and view order

穿精又带淫゛_ 提交于 2019-12-18 04:55:17
问题 I've created a custom field for warranty in my products pages, via function.php. add_action( 'woocommerce_product_options_general_product_data', 'test_custom_fields' ); function test_custom_fields() { // Print a custom text field woocommerce_wp_text_input( array( 'id' => '_warranty', 'label' => 'i.e. 15 years', 'description' => '', 'desc_tip' => 'true', 'placeholder' => 'i.e. 15 years' ) ); } add_action( 'woocommerce_process_product_meta', 'test_save_custom_fields' ); function test_save

Get the email id in Woocommerce emails

巧了我就是萌 提交于 2019-12-18 04:25:11
问题 I have custom statuses and custom emails set up in Woocommerce. I would like to use the current email, WC_Email , not the current status as a variable inside email templates. I need to have some if statements in the email templates. I am not using the order status to ensure if an email from an order gets resent manually it doesn't send data for the current order status with an separate email. How can I echo the WC_Email email ID as a variable in Woocommerce? 回答1: The wc_order_email class or

Get all Orders IDs from a product ID in Woocommerce

亡梦爱人 提交于 2019-12-17 21:34:20
问题 How can I get an array with Order IDs by Product ID? I mean receive all orders where specific product is presented. I know how to do this by MySQL, but is there a way to do this by WP_Query function? 回答1: Updates: 2017 - SQL query changed to "SELECT DISTINCT" instead of "SELECT" to avoid duplicated Order IDs in the array (then no need of array_unique() to filter duplicates…). 2019 - Enabled product variation type support in the SQL Query Then you can embed this in a custom function with

WooCommerce - Hide other shipping methods when FREE SHIPPING is available

倖福魔咒の 提交于 2019-12-17 07:55:41
问题 I would like to hide other shipping options when free shipping is available on Woocommerce. Because latest version of woocommerce now is still showing other shipping options even if there's FREE shipping option. Please help 回答1: There is this recent code snippet for WooCommerce 2.6+. that you can Use: add_filter( 'woocommerce_package_rates', 'hide_other_shipping_when_free_is_available', 100, 2 ); function hide_other_shipping_when_free_is_available( $rates, $package ) { $free = array();

WooCommerce - Hide other shipping methods when FREE SHIPPING is available

风格不统一 提交于 2019-12-17 07:54:01
问题 I would like to hide other shipping options when free shipping is available on Woocommerce. Because latest version of woocommerce now is still showing other shipping options even if there's FREE shipping option. Please help 回答1: There is this recent code snippet for WooCommerce 2.6+. that you can Use: add_filter( 'woocommerce_package_rates', 'hide_other_shipping_when_free_is_available', 100, 2 ); function hide_other_shipping_when_free_is_available( $rates, $package ) { $free = array();

Check if a customer has purchased a specific products in WooCommerce

余生颓废 提交于 2019-12-17 06:14:28
问题 I need to check if a customer has purchased a specific product earlier in WooCommerce. The case is this: The customer shall not be able to purchase product "c", "d", "e" unless they have purchased product "a" or "b" at an earlier time. If the customer has purchased product "a" or "b" earlier, then the purchase button of product "c", "d" and "e" is activated and they are allowed to buy them. If they haven´t purchased "a" or "b" earlier, they will not be allowed to purchase "c", "d", "e" and

Check if a customer has purchased a specific products in WooCommerce

前提是你 提交于 2019-12-17 06:14:14
问题 I need to check if a customer has purchased a specific product earlier in WooCommerce. The case is this: The customer shall not be able to purchase product "c", "d", "e" unless they have purchased product "a" or "b" at an earlier time. If the customer has purchased product "a" or "b" earlier, then the purchase button of product "c", "d" and "e" is activated and they are allowed to buy them. If they haven´t purchased "a" or "b" earlier, they will not be allowed to purchase "c", "d", "e" and

Total count for each order item in a loop on Woocommerce

﹥>﹥吖頭↗ 提交于 2019-12-13 20:19:49
问题 Hi I'm learning PHP and Woocommerce at the same time! I'm trying to get all the orders which have status processing and the total count for each and display this on a page. Thus far I can loop through all the orders and get the name and quantity of each. but as I don't know which product is going to be in the list, I'm not sure how I would compare the name and then add the quantity. My current output is like this: prod1 - v1 x 1 Prod2 - v3 x 1 prod2 - v3 x 1 prod3 - v2 x 11 prod3 - v2 x 1

Exclude specific products on auto-complete orders process in Woocommerce

笑着哭i 提交于 2019-12-13 18:19:25
问题 I’m currently using the code from this answer thread to auto-complete orders so that new WooCommerce bookings are added to the calendar, (They only get added once marked as complete). This works great for bookings, however, I’d like to exclude some other products from auto-completing. Do you know if this is possible? 回答1: Iterating through order items is a heavier process , than making a much more lighter SQL query. Here is a custom conditional function that will check for products Ids in a