首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WooCommerce取代购物车/结帐中基于产品类别的“备用单上可用”

WooCommerce取代购物车/结帐中基于产品类别的“备用单上可用”
EN

Stack Overflow用户
提问于 2020-04-17 14:08:27
回答 2查看 4.2K关注 0票数 4

我编写了一些代码,用于在基于产品类别的产品详细信息页上显示自定义后台订单消息。

代码语言:javascript
复制
function custom_backorder_message( $text, $product ){
    if ( $product->managing_stock() && $product->is_on_backorder( 1 ) ) {

        if( has_term( 'bridal-line', 'product_cat' ) ) {
            $text = __( 'Your piece will be handcrafted for you. Upon order we will manufacture your piece of eternity. Sadly, we can not give you a timeline, due to Covid 19, but are expecting 5-7 weeks', 'text-domain' );
        }else {
            $text = __( 'This product is currently out of stock, but upon order we will handcraft your piece. Sadly, we can not give you a timeline, due to Covid 19, but are expecting 6-8 week.', 'text-domain' );
        }
    }
    return $text;
}
add_filter( 'woocommerce_get_availability_text', 'custom_backorder_message', 10, 2 );

现在,在购物车页面上显示“backorder上可用的”。我怎样才能在那里显示正确的回序信息?

任何帮助都是非常感谢的!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-04-17 15:35:47

用途:woocommerce_cart_item_backorder_notification

注意,第三个参数($product_id)是由has_term指定的,这是因为默认使用当前post(ID)。但是,如果购物车中有多个产品,那么就有多个ID.

代码语言:javascript
复制
// Change backorder notification - Single product page
function custom_availability_text( $text, $product ) {
    // Returns whether or not the product is stock managed.
    if ( $product->managing_stock() && $product->is_on_backorder( 1 ) ) {
        // Check if the current post has any of given terms.
        if( has_term( 'bridal-line', 'product_cat' ) ) {
            $text = __( 'My first text', 'woocommerce' );
        } else {
            $text = __( 'My second text', 'woocommerce' );
        }
    }
    return $text;
}
add_filter( 'woocommerce_get_availability_text', 'custom_availability_text', 10, 2 );

// Change backorder notification - Shop page
function custom_cart_item_backorder_notification( $html, $product_id ){
    // Check if the current post has any of given terms.
    if ( has_term( 'bridal-line', 'product_cat', $product_id ) ) {
        $html = '<p class="backorder_notification">' . esc_html__( 'My first text', 'woocommerce' ) . '</p>';
    } else {
        $html = '<p class="backorder_notification">' . esc_html__( 'My second text', 'woocommerce' ) . '</p>';
    }

    return $html;
}
add_filter( 'woocommerce_cart_item_backorder_notification', 'custom_cart_item_backorder_notification', 10, 2 );
票数 5
EN

Stack Overflow用户

发布于 2020-06-20 08:16:02

我的主题的function.php中的这段代码适用于我:

代码语言:javascript
复制
function change_specific_availability_text( $availability ) {

    $targeted_text = __( 'Available on backorder', 'woocommerce' );

    if ($availability[ 'class' ] == 'available-on-backorder' && $availability[ 'availability' ] == $targeted_text) {

        $availability[ 'availability' ] = __( 'In the central warehouse', 'your-theme-textdomain' );

    }

    return $availability;

}

add_filter( 'woocommerce_get_availability', 'change_specific_availability_text', 20, 1 );

或替代的、简化的方式:

代码语言:javascript
复制
function change_specific_availability_text( $availability ) {

    if ($availability[ 'class' ] == 'available-on-backorder') {

        $availability[ 'availability' ] = __( 'In the central warehouse', 'your-theme-textdomain' );

    }

    return $availability;

}

add_filter( 'woocommerce_get_availability', 'change_specific_availability_text', 20, 1 );
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61273620

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档