Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * WooCommerce:
- * Save the free shipping methodminimum amount (if set) within the order data when a free shipping method is selected
- */
- add_action( 'woocommerce_checkout_create_order', 'wpo_safe_free_shipping_amount_within_order_data' );
- function wpo_safe_free_shipping_amount_within_order_data( $order ) {
- $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' );
- // If a free shipping method is selected...
- if ( strpos( $chosen_shipping_methods[0], 'free_shipping' ) !== false ) {
- list( $shipping_name, $shipping_id ) = explode( ':', $chosen_shipping_methods[0] );
- // ...get the minimum amount from its settings
- $free_shipping_settings = get_option( "woocommerce_{$shipping_name}_{$shipping_id}_settings" );
- $min_amount = $free_shipping_settings['min_amount'];
- // If there is a minimum amount set, save it within the order data
- if ( ! empty( $min_amount ) ) {
- $order->update_meta_data( '_free_shipping_min_amount', $min_amount );
- $order->save();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement