woocommerce

Allow proceed to checkout for non mixed defined product categories in Woocommerce

独自空忆成欢 提交于 2021-02-05 08:31:44
问题 In woocommerce I am trying to avoid proceed to checkout when cart items are from mixed product categories… The following code is mostly working as I intended: function sv_wc_prevent_checkout_for_category() { // set the slug of the category that cannot be mixed from other categories $category = 'test'; // get the product category $product_cat = get_term_by( 'slug', $category, 'product_cat' ); // sanity check to prevent fatals if the term doesn't exist if ( is_wp_error( $product_cat ) ) {

Get order subtotal value in WooCommerce

痞子三分冷 提交于 2021-02-05 08:28:30
问题 I use the module for calculating delivery by local carrier, but the module don't calculate shipping costs to the total. In the wp-content/plugins/woocommerce/templates/order/order-details.php I added the following code to take the amount of shipping and subtotal: <?php $a = array( get_post_meta($order_id, 'Order_subtotal', true), get_post_meta($order_id, 'Econt_Customer_Shipping_Cost', true)); ?> <tr class="total-cost"> <th><?php _e( 'Total:', 'woocommerce'); ?></th> <td><?php echo array_sum(

Redirection for non checkout guest allowed in WooCommerce

陌路散爱 提交于 2021-02-05 08:22:27
问题 After Allow guest checkout for specific products only in WooCommerce answer to my previous question, the following code redirect users to login page: add_action( 'template_redirect', 'checkout_redirect_non_logged_to_login_access'); function checkout_redirect_non_logged_to_login_access() { if( is_checkout() && !is_user_logged_in()){ wp_redirect( get_permalink( get_option('woocommerce_myaccount_page_id') ) ); exit; } } But I have some products which allows guest checkout (see the linked

How to reduce the stock for specific order status in WooCommerce

折月煮酒 提交于 2021-02-05 08:21:45
问题 I am managing my stock on WooCommerce. I would like to reduce the stock when the order status changes to a specific status for example (pending) or other status. So I used this code: function manageStock ($order_id, $old_status, $new_status, $instance ) { if ($old_status === 'on-hold'){ wc_reduce_stock_levels($order_id); } } add_action( 'woocommerce_order_status_changed', 'manageStock', 10, 4 ); But unfortunately does not work. Is there another way to solve this problem? 回答1: Stock is already

How to reduce the stock for specific order status in WooCommerce

跟風遠走 提交于 2021-02-05 08:21:29
问题 I am managing my stock on WooCommerce. I would like to reduce the stock when the order status changes to a specific status for example (pending) or other status. So I used this code: function manageStock ($order_id, $old_status, $new_status, $instance ) { if ($old_status === 'on-hold'){ wc_reduce_stock_levels($order_id); } } add_action( 'woocommerce_order_status_changed', 'manageStock', 10, 4 ); But unfortunately does not work. Is there another way to solve this problem? 回答1: Stock is already

Check a product category for a product in Woocommerce

女生的网名这么多〃 提交于 2021-02-05 08:16:06
问题 I want to check the category of a WooCommerce product post right after it's created(or updated) and then run some more code based on the category. To check post on creation/update I used save_post and for category has_category . Something goes wrong with has_category and it doesn't return anything at all. I tried replacing $post_id with $post and $post->ID as suggested in other issues but that didn't change anything. function doFruitStuff($post_id){ // Function in functions.php $fruits =

Add a new custom field to WooCommerce checkout

吃可爱长大的小学妹 提交于 2021-02-05 08:14:49
问题 I have the code that should work, but for some reason it doesnt. I want to add a new custom field called "City" under Woocommerce checkout, using this code: // Display a custom checkout select field after Billing form add_action( 'woocommerce_after_checkout_billing_form', 'my_custom_checkout_field', 10, 1 ); function my_custom_checkout_field( $checkout ) { echo '<div id="my_custom_checkout_field"> ' . __('City') . ''; woocommerce_form_field( 'delivery_date', array( 'type' => 'select',

Display a product custom field only in WooCommerce Admin single orders

戏子无情 提交于 2021-02-05 08:13:18
问题 This question follows How to show a product custom field (custom SKU) in WooCommerce orders answer to my previous question. How do I make a product custom field articleid (custom SKU) to be visible only in Admin Order edit pages for each order item? Also, it does not work for manual orders. How to display a product custom field articleid (custom SKU) on manual orders too ? 回答1: Updated last function to avoid errors with other order item types that "line items". To make it only visible on

WooCommerce: Get custom field from product variations and display it as a suffix to variation prices

﹥>﹥吖頭↗ 提交于 2021-02-05 07:51:34
问题 I'm trying to get a value from a custom numbers field on product variations, and show it as a suffix to variation prices along with custom text. I'm working from WooCommerce: Get custom field from product variations and display it on the “additional information area” Adding custom text to the variation price in Woocommerce This is what I have: // 1. Add custom field input @ Product Data > Variations > Single Variation add_action( 'woocommerce_variation_options_pricing', 'Add_bulk_price_to

Woocommerce: Programmatically Update Item In Cart

不问归期 提交于 2021-02-05 07:42:23
问题 I need to programmatically and dynamically change the price of an item in the cart. I’ve tried varying combinations of Woocommerce action hooks, the cart and session objects, but nothing quite seems to do the trick. I thought this wouldn’t be so challenging. add_action( 'woocommerce_before_calculate_totals', 'change_cart_item_price' ); function change_cart_item_price( $cart_object ) { foreach ( $cart_object->cart_contents as $key => $value ) { if( 123 == $value['data']->id ) { $new_price =