猿问

WooCommerce 更改产品可用性的尺寸和颜色

我有此代码可以在产品详细信息页面中显示产品可用性。我想编辑显示的可用性的字体大小和颜色。


谁能帮我?


add_filter( 'woocommerce_get_availability', 'wcs_custom_get_availability', 1, 2);

function wcs_custom_get_availability( $availability, $_product ) {

    

    // Change In Stock Text

    if ( $_product->is_in_stock() ) {

        $availability['availability'] = __('Verfügbar', 'woocommerce') ;

    }

    // Change Out of Stock Text

    if ( ! $_product->is_in_stock() ) {

        $availability['availability'] = __('Leider ausverkauft!', 'woocommerce');

    }

    return $availability;

}


慕容708150
浏览 105回答 1
1回答

斯蒂芬大帝

请改用以下内容:add_filter( 'woocommerce_get_availability', 'filter_wc_get_availability', 10, 2);function filter_wc_get_availability( $availability, $product ) {&nbsp; &nbsp; // In stock&nbsp; &nbsp; if ( 'in-stock' ===&nbsp; $availability['class'] ) {&nbsp; &nbsp; &nbsp; &nbsp; $availability['availability'] = __('Verfügbar', 'woocommerce');&nbsp; &nbsp; }&nbsp; &nbsp; // Out of stock&nbsp; &nbsp; elseif ( 'out-of-stock' ===&nbsp; $availability['class'] ) {&nbsp; &nbsp; &nbsp; &nbsp; $availability['availability'] = __('Leider ausverkauft!', 'woocommerce');&nbsp; &nbsp; }&nbsp; &nbsp; return $availability;}内联 CSS 样式规则(可以添加到主题的 styles.ccs 文件中):add_action('wp_head', 'product_availability_css_styling_rules', 9990 );function product_availability_css_styling_rules() {&nbsp; &nbsp; // Only on single product pages&nbsp; &nbsp; if( is_product() ):&nbsp; &nbsp; ?><style>&nbsp; &nbsp; &nbsp; &nbsp; .stock.in-stock {font-size: 13px !important; color: #0f834d;}&nbsp; &nbsp; &nbsp; &nbsp; .stock.out-of-stock {font-size: 13px !important; color: #e2401c;}&nbsp; &nbsp; </style><?php&nbsp; &nbsp; endif;}代码位于活动子主题(或活动主题)的functions.php 文件中。经过测试并有效。
随时随地看视频慕课网APP
我要回答