本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长

+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

暂无数据

Change back-order message for products with certain SKU's in WooCommerce

发布于2023-05-25 21:35     阅读(755)     评论(0)     点赞(12)     收藏(1)


I would like to have a custom back-order message for certain WooCommerce products based on their ID, SKU or something else unique.

Right now I have this, and this works fine for all products that have back-order enabled, but what if I want this logic conditional for only certain product variations?

function backorder_text($availability) {
    if($product->get_sku() == "111100"){
        foreach($availability as $i) {
            //$availability = str_replace('Available on backorder', 'Yo, allow 3-4 weeks for your shiz!', $availability);
            $availability = str_replace('Beschikbaar via nabestelling', 'UITVERKOCHT (U kunt wel bestellen, maar de levertijd is 2-3 werkdagen).', $availability);
        }
        return $availability; 
    }
}
add_filter('woocommerce_get_availability', 'backorder_text');

解决方案


This actually worked best for me:

function backorder_text_prikkabel_zonder_fittingen( $availability, $product ) {
    $product_ids = array( 7631, 7631, 8612, 7629, 7628, 7627 ); 
    if ( in_array( $product->get_id(), $product_ids ) ){ 
        foreach( $availability as $i ) {
            $availability = str_replace( 'Default back-order message', 'Your custom back-order message', $availability );
        }
    }
    return $availability;
}
add_filter('woocommerce_get_availability', 'backorder_text_prikkabel_zonder_fittingen', 10, 2 );

Explanation: the array contains a list of product variation ID's. If you echo $product->get_id(), somewhere around the bottom of the page, you will see a list of ID's for each of the products variations for that product.

Make sure the default order message exactly matches the message you get on your product page so the custom message will be used instead.



所属网站分类: 技术文章 > 问答

作者:黑洞官方问答小能手

链接:http://www.phpheidong.com/blog/article/546152/007dfe573ba3ad8d791d/

来源:php黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

12 0
收藏该文
已收藏

评论内容:(最多支持255个字符)