[WordPress] Woocomerce 設定カテゴリ最小カート

スポンサーリンク

Question

ブロック特定 woocomerce カテゴリー価格を好きだろう今動作のみすべてのカテゴリの woocomerce 私のコードです。私のカテゴリの名前は: ストック。このカテゴリの使用のみを目的です

たいユーザー場合株式を購入する最小 1200年を購入する必要があるカテゴリ

    // Set a minimum dollar amount per order
add_action( 'woocommerce_check_cart_items', 'spyr_set_min_total' );
function spyr_set_min_total() {
    // Only run in the Cart or Checkout pages
    if( is_cart() || is_checkout() ) {
        global $woocommerce;

        // Set minimum cart total
        $minimum_cart_total = 1200;

        // Total we are going to be using for the Math
        // This is before taxes and shipping charges
        $total = WC()->cart->subtotal;

        // Compare values and add an error is Cart's total
        // happens to be less than the minimum required before checking out.
        // Will display a message along the lines of
        // A Minimum of 10 USD is required before checking out. (Cont. below)
        // Current cart total: 6 USD 
        if( $total <= $minimum_cart_total  ) {
            // Display our error message
            wc_add_notice( sprintf( 'A Minimum of %s %s is required before checking out.'
                .'
Current cart\'s total: %s %s', $minimum_cart_total, get_option( 'woocommerce_currency'), $total, get_option( 'woocommerce_currency') ), 'error' ); } } }

答え

以下のコードを試す:

    add_action( 'woocommerce_check_cart_items', 'spyr_set_min_total' );
    function spyr_set_min_total() {
        // Only run in the Cart or Checkout pages
        if( is_cart() || is_checkout() ) {

            global $woocommerce, $product;
            $i=0;
            //loop through all cart products
            foreach ( $woocommerce->cart->cart_contents as $product ) :


                // Set minimum cart total
                $minimum_cart_total = 1200;

                // Total we are going to be using for the Math
                // This is before taxes and shipping charges
                $total = WC()->cart->subtotal;

                // See if any product is from the STOCK category or not
                if ( has_term( '1441', 'product_cat', $product['product_id'] ) ) :

                    //Get price of that product
                    $regular_price = get_post_meta($product['product_id'], '_sale_price', true); //change to _sale_price if it is in sale
                    //echo $regular_price."
"; $total = $regular_price * $product['quantity']; //echo $total."
"; $subtotal_cat += $total; //get total of //echo $subtotal_cat; //$category_price += ( $product['line_subtotal'] + $product['line_subtotal_tax'] ); endif; endforeach; foreach ( $woocommerce->cart->cart_contents as $product ) : if ( has_term( '11', 'product_cat', $product['product_id'] ) ) : // Compare values and add an error is Cart's total // happens to be less than the minimum required before checking out. // Will display a message along the lines of // A Minimum of 10 USD is required before checking out. (Cont. below) // Current cart total: 6 USD if( $subtotal_cat <= $minimum_cart_total ) { // Display our error message wc_add_notice( sprintf( 'A Minimum of %s %s is required from stock category before checking out.' .'
Current cart\'s total: %s %s', $minimum_cart_total, get_option( 'woocommerce_currency'), $subtotal_cat, get_option( 'woocommerce_currency') ), 'error' ); } endif; endforeach; } }

教えてください出力.

http://stackoverflow.com/questions/27777804/woocomerce-set-category-minimum-cart

スポンサーリンク

Leave a Reply