복붙노트

[WORDPRESS] 배송 방법에 따라 변경 Woocommerce 주문 상태

WORDPRESS

배송 방법에 따라 변경 Woocommerce 주문 상태

해결법


  1. 1.나는 배송 방법 ID는 (슬러그의 종류 등) 소문자로 항상 곁에있다 대신로 ()는 빠르고 적은 메모리 집약적 인 기능 strpos를 사용하는 것을 선호합니다.

    나는 배송 방법 ID는 (슬러그의 종류 등) 소문자로 항상 곁에있다 대신로 ()는 빠르고 적은 메모리 집약적 인 기능 strpos를 사용하는 것을 선호합니다.

    그래서 더 가능한 방법을 사용하여,이 경우의 WC_Order_Item_Shipping 객체 데이터를 얻을 수있다.

    그래서에게 코드가 있어야한다 :

    add_action( 'woocommerce_thankyou', 'express_shipping_update_order_status', 10, 1 );
    function express_shipping_update_order_status( $order_id ) {
        if ( ! $order_id ) return;
        
        $search = 'express'; // The needle to search in the shipping method ID
    
        // Get an instance of the WC_Order object
        $order = wc_get_order( $order_id );
    
        // Get the WC_Order_Item_Shipping object data
        foreach($order->get_shipping_methods() as $shipping_item ){
            // When "express delivery" method is used, we change the order to "on-hold" status
            if( strpos( $shipping_item->get_method_title(), $search ) !== false && ! $order->has_status('on-hold')){
                $order->update_status('on-hold');
                break;
            }
        }
    }
    

    코드는 플러그인 파일도 function.php의 활성 자식 테마 (또는 테마)의 파일이나 간다.

    테스트 및 작품 ...


  2. 2.위의 코드는 나를 위해 일을하지 않았다 그래서 나는 내가 그것을 디버깅 FB 그룹의 도움에 사람이 있고이 나를 위해 일한 마지막 하나

    위의 코드는 나를 위해 일을하지 않았다 그래서 나는 내가 그것을 디버깅 FB 그룹의 도움에 사람이 있고이 나를 위해 일한 마지막 하나

    ADD_ACTION ( 'woocommerce_thankyou', 'express_shipping_update_order_status', 10, 1); 기능 express_shipping_update_order_status ($ ORDER_ID) { (! $ ORDER_ID) 반환하는 경우; $ 검색 = '표현'; // 바늘은 배송 방법 ID를 검색하는 // WC_Order 객체의 인스턴스를 가져옵니다 $ 순서 = wc_get_order ($ ORDER_ID); // WC_Order_Item_Shipping 객체 데이터를 가져옵니다 foreach는 ($ 순서 -> $ shipping_item로 get_shipping_methods ()) { "특급 배달"방법을 사용하는 경우 // 우리는 '보류'상태로 순서를 변경 경우 (strpos ($ shipping_item-> get_method_title (). $ 것은) 검색! == 거짓을) { $ 순서 -> update_status ( '보류'); $ 순서 -> 저장 (); 단절; } } }

  3. from https://stackoverflow.com/questions/47286158/change-woocommerce-order-status-based-on-shipping-method by cc-by-sa and MIT license