ThaiSEOBoard.com

พัฒนาเว็บไซต์ => CMS & Free Script => ข้อความที่เริ่มโดย: jessicatan ที่ 05 กันยายน 2018, 11:11:31



หัวข้อ: ช่วยแก้โค้ดหน่อยค่ะ (wordpress)
เริ่มหัวข้อโดย: jessicatan ที่ 05 กันยายน 2018, 11:11:31
(https://www.picz.in.th/images/2018/09/05/fx4FpQ.jpg)

จากรูปคือ เมื่อใส่โค้ดด้านล่างแล้ว มันแสดงข้อความใน วงเล็บค่ะ คำถามคือ จะเอาในส่วนของวงเล็บออกยังไงเกี่ยวกับโค้ดมั้ย โค้ดมาจากที่นี่>>https://stackoverflow.com/questions/45823061/rename-add-to-cart-buttons-for-out-of-stock-products-in-woocommerce-3

add_filter( 'woocommerce_product_add_to_cart_text', 'customizing_add_to_cart_button_text', 10, 2 );
add_filter( 'woocommerce_product_single_add_to_cart_text', 'customizing_add_to_cart_button_text', 10, 2 );
function customizing_add_to_cart_button_text( $button_text, $product ) {

    $sold_out = __( "Sold Out", "woocommerce" );

    $availability = $product->get_availability();
    $stock_status = $availability['class'];

    // Only for variable products on single product pages
    if ( $product->is_type('variable') && is_product() )
    {
    ?>
    <script>
    jQuery(document).ready(function($) {
        $('select').blur( function(){
            if( '' != $('input.variation_id').val() && $('p.stock').hasClass('out-of-stock') )
                $('button.single_add_to_cart_button').html('<?php echo $sold_out; ?>');
            else
                $('button.single_add_to_cart_button').html('<?php echo $button_text; ?>');

            console.log($('input.variation_id').val());
        });
    });
    </script>
    <?php
    }
    // For all other cases (not a variable product on single product pages)
    elseif ( ! $product->is_type('variable') && ! is_product() )
    {
        if($stock_status == 'out-of-stock')
            $button_text = $sold_out.' ('.$stock_status.')';
        else
            $button_text.=' ('.$stock_status.')';
    }
    return $button_text;
}


หัวข้อ: Re: ช่วยแก้โค้ดหน่อยค่ะ (wordpress)
เริ่มหัวข้อโดย: thanoo001 ที่ 05 กันยายน 2018, 11:55:20
ไม่เคยขายของนะครับ ผมเลยไม่ได้ใช้ woocommerce ไม่รู้ว่าจะทำงานถูกป่าว ลองดูได้ครับ
โค๊ด:
add_filter( 'woocommerce_product_add_to_cart_text', 'customizing_add_to_cart_button_text', 10, 2 );
add_filter( 'woocommerce_product_single_add_to_cart_text', 'customizing_add_to_cart_button_text', 10, 2 );
function customizing_add_to_cart_button_text( $button_text, $product ) {

    $sold_out = __( "Sold Out", "woocommerce" );

    $availability = $product->get_availability();
    $stock_status = $availability['class'];

    // Only for variable products on single product pages
    if ( $product->is_type('variable') && is_product() )
    {
    ?>
    <script>
    jQuery(document).ready(function($) {
        $('select').blur( function(){
            if( '' != $('input.variation_id').val() && $('p.stock').hasClass('out-of-stock') )
                $('button.single_add_to_cart_button').html('<?php echo $sold_out?>');
            else
                $('button.single_add_to_cart_button').html('<?php echo $button_text?>');

            console.log($('input.variation_id').val());
        });
    });
    </script>
    <?php
    
}
    
// For all other cases (not a variable product on single product pages)
    
elseif ( ! $product->is_type('variable') && ! is_product() ) 
    {
        if(
$stock_status == 'out-of-stock')
            
$button_text $sold_out;
        else
            
$button_text.='';
    }
    return 
$button_text;
}


หัวข้อ: Re: ช่วยแก้โค้ดหน่อยค่ะ (wordpress)
เริ่มหัวข้อโดย: toekingsize ที่ 05 กันยายน 2018, 12:11:30
ลบ ('.$stock_status.') ทิ้งได้เลย


หัวข้อ: Re: ช่วยแก้โค้ดหน่อยค่ะ (wordpress)
เริ่มหัวข้อโดย: jessicatan ที่ 05 กันยายน 2018, 13:08:24
ไม่เคยขายของนะครับ ผมเลยไม่ได้ใช้ woocommerce ไม่รู้ว่าจะทำงานถูกป่าว ลองดูได้ครับ
โค๊ด:
add_filter( 'woocommerce_product_add_to_cart_text', 'customizing_add_to_cart_button_text', 10, 2 );
add_filter( 'woocommerce_product_single_add_to_cart_text', 'customizing_add_to_cart_button_text', 10, 2 );
function customizing_add_to_cart_button_text( $button_text, $product ) {

    $sold_out = __( "Sold Out", "woocommerce" );

    $availability = $product->get_availability();
    $stock_status = $availability['class'];

    // Only for variable products on single product pages
    if ( $product->is_type('variable') && is_product() )
    {
    ?>
    <script>
    jQuery(document).ready(function($) {
        $('select').blur( function(){
            if( '' != $('input.variation_id').val() && $('p.stock').hasClass('out-of-stock') )
                $('button.single_add_to_cart_button').html('<?php echo $sold_out?>');
            else
                $('button.single_add_to_cart_button').html('<?php echo $button_text?>');

            console.log($('input.variation_id').val());
        });
    });
    </script>
    <?php
    
}
    
// For all other cases (not a variable product on single product pages)
    
elseif ( ! $product->is_type('variable') && ! is_product() ) 
    {
        if(
$stock_status == 'out-of-stock')
            
$button_text $sold_out;
        else
            
$button_text.='';
    }
    return 
$button_text;
}


ได้แล้วค่ะ ขอบคุณมากค่ะ  :wanwan017: :wanwan017:


หัวข้อ: Re: ช่วยแก้โค้ดหน่อยค่ะ (wordpress)
เริ่มหัวข้อโดย: jessicatan ที่ 05 กันยายน 2018, 13:09:02
ลบ ('.$stock_status.') ทิ้งได้เลย

 :wanwan017:


หัวข้อ: Re: ช่วยแก้โค้ดหน่อยค่ะ (wordpress)
เริ่มหัวข้อโดย: yokphet ที่ 07 กันยายน 2018, 11:23:41
ขอเก็บข้อมูลนะ