0

家の ASP.NET 側から WP を初めて使用します。WP 3.8.1 を woocommerce の USPS および FEDEX エクステンションと共に使用して、可燃性で航空便で発送できない製品のチェックアウト ページに表示される FEDEX 地上料金以外をすべて除外しようとしています。関数を作成し、テーマの functions.php ファイルに配置しました。私は働きません。add_filter で間違ったタグを使用している可能性があります。

これを考え出した。そのため、必要な人のために元のコードを編集しました。

製品 ID はハードコーディングされており、さらに開発が必要です。利用可能なメソッド文字列は、それらを公開するために print_r を実行する必要があると考えるまでは困難でした。それらを公開するには、その行のコメントを外します。これらは woocommerce USPS および FEDEX 拡張機能に特有のものであり、文書化されていない可能性があります。

    // Hide USPS shipping methods when flammable items in cart 
    add_filter( 'woocommerce_available_shipping_methods', 'hide_usps_when_flammable_in_cart' , 1 );

    /** Hide usps shipping when flammable items in cart
        @param array $available_methods 
    */ 
    function hide_usps_when_flammable_in_cart( $available_methods ) {
         // printing the methods so I know the available methods to exclude
         // echo "<pre>" . print_r( $available_methods, true ) . "</pre>";
        global $woocommerce;
         // Get all products in cart
        $products = $woocommerce->cart->get_cart();
        //store product id's in array
        $volitile = array(170,191,192,194,196,199,201,204,206,208,209,210,212,214,217,262);

        // loop through the items looking for one in the ineligible array
        foreach ( $products as $key => $item ) {
            if( in_array( $item['product_id'], $volitile ) ) {
                unset($available_methods['usps:flat_rate_box_priority']);
                unset($available_methods['usps:flat_rate_box_express']);
                unset($available_methods['usps:D_PRIORITY_MAIL']);
                unset($available_methods['usps:D_STANDARD_POST']);
                unset($available_methods['fedex:FEDEX_EXPRESS_SAVER']);
                unset($available_methods['fedex:FEDEX_2_DAY_AM']);
                unset($available_methods['fedex:FIRST_OVERNIGHT']);
                unset($available_methods['fedex:PRIORITY_OVERNIGHT']);
                unset($available_methods['fedex:FEDEX_2_DAY']);
                unset($available_methods['fedex:STANDARD_OVERNIGHT']);
                break;
            }
        }

        return $available_methods;
    } 
4

0 に答える 0