woocommerce

Woocommerce: Programmatically Update Item In Cart

泄露秘密 提交于 2021-02-05 07:42:00
问题 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 =

How to get WooCommerce shipping methods cost and settings?

烈酒焚心 提交于 2021-02-05 07:35:43
问题 I'm trying to get all shipping methods, with their rates and title. But when i use WC()->shipping->get_shipping_methods() it will only return empty rates array, and empty title string. Here is a dump: array (size=3) 'flat_rate' => object(WC_Shipping_Flat_Rate)[1861] protected 'fee_cost' => string '' (length=0) public 'supports' => array (size=3) 0 => string 'shipping-zones' (length=14) 1 => string 'instance-settings' (length=17) 2 => string 'instance-settings-modal' (length=23) public 'id' =>

Add customer note from another script in WooCommerce

拈花ヽ惹草 提交于 2021-02-05 07:09:25
问题 I have a script that changes the status of orders based on our ERP system. In addition to that, we need to add customer notes. I found the way to do it: $order->add_order_note($note); $order->save(); Unfortunately this won't work outside the order edit screen, I tried to run it from my custom plugin. (source) If I do it via $order->update_status($status, $note); it only updates the status. Is there a way to add a note outside the edit screen? (Including e-mailing the customer) 回答1: If the

Change “View Cart” and “Checkout” buttons text in Cart Widget Woocommerce

谁说我不能喝 提交于 2021-02-05 06:35:09
问题 I'm trying to find the correct function or filter to edit the text of the buttons "View Cart" and "Checkout" in the Cart Widget of Woocommerce. My website url : http://modularwave.com/ (just so you know i'm using Brutal, great theme from zigzagpress). Thanks in advance for you help, F. 回答1: You can use str_ireplace() to change the text of the button, the following function will allow you to change the text of a Woocommerce button: //The filters.. both are required. add_filter('gettext',

Change “View Cart” and “Checkout” buttons text in Cart Widget Woocommerce

允我心安 提交于 2021-02-05 06:35:07
问题 I'm trying to find the correct function or filter to edit the text of the buttons "View Cart" and "Checkout" in the Cart Widget of Woocommerce. My website url : http://modularwave.com/ (just so you know i'm using Brutal, great theme from zigzagpress). Thanks in advance for you help, F. 回答1: You can use str_ireplace() to change the text of the button, the following function will allow you to change the text of a Woocommerce button: //The filters.. both are required. add_filter('gettext',

Add a custom checkout field based on cart items quantity in Woocommerce

做~自己de王妃 提交于 2021-02-05 06:17:05
问题 Ultimately I am trying to add a field to checkout in woocommerce when a customer has over a certain quantity in their checkout. For this example I am using 500 and just trying to get a message to show at the bottom of checkout. I have been trying various variations of code and this is what I have so far. add_action( 'woocommerce_after_checkout_form', 'woocommerce_add_quantity_message', 12 ); function woocommerce_add_quantity_message() { global $woocommerce; $total_products = 0; foreach (

Add a custom checkout field based on cart items quantity in Woocommerce

点点圈 提交于 2021-02-05 06:17:05
问题 Ultimately I am trying to add a field to checkout in woocommerce when a customer has over a certain quantity in their checkout. For this example I am using 500 and just trying to get a message to show at the bottom of checkout. I have been trying various variations of code and this is what I have so far. add_action( 'woocommerce_after_checkout_form', 'woocommerce_add_quantity_message', 12 ); function woocommerce_add_quantity_message() { global $woocommerce; $total_products = 0; foreach (

Add a custom ajax button to WooCommerce admin orders list

孤街醉人 提交于 2021-02-05 05:57:57
问题 I am creating a plugin to track courier order via button in shop order page. This is my code // add Tracking button in shop order admin column add_action( 'manage_shop_order_posts_custom_column', 'dvs_add_tracking_admin_list_column_content' ); function dvs_add_tracking_admin_list_column_content( $column ) { <button type="button" class="woocommerce-Button button mark-as-read" >Track Order</button> <?php } ?> <script type="text/javascript"> jQuery(function($){ // use jQuery code inside this to

Add sorting by stock quantity in WooCommerce products sort by

我的梦境 提交于 2021-02-04 21:42:36
问题 I have added the following code to my theme functions.php . The "Availability" sort option does show up but when I select it, it is sorted by Title, not stock quantity. I also tried using stock_quantity as a meta_key (even though it's not a meta) and that didn't work either. add_filter( 'woocommerce_get_catalog_ordering_args', 'custom_woocommerce_get_catalog_ordering_args' ); function custom_woocommerce_get_catalog_ordering_args( $args ) { $orderby_value = isset( $_GET['orderby'] ) ? wc_clean

Add sorting by stock quantity in WooCommerce products sort by

余生颓废 提交于 2021-02-04 21:42:30
问题 I have added the following code to my theme functions.php . The "Availability" sort option does show up but when I select it, it is sorted by Title, not stock quantity. I also tried using stock_quantity as a meta_key (even though it's not a meta) and that didn't work either. add_filter( 'woocommerce_get_catalog_ordering_args', 'custom_woocommerce_get_catalog_ordering_args' ); function custom_woocommerce_get_catalog_ordering_args( $args ) { $orderby_value = isset( $_GET['orderby'] ) ? wc_clean