在Woocommerce单个产品页面上显示产品运输类别

时间:2019-03-01 14:01:33

标签: php wordpress woocommerce shipping taxonomy-terms

我试图在产品页面上显示运输类别,但是我必须做错什么,因为什么也没显示。

我在function.php中使用了以下代码:

add_action('woocommerce_single_product_summary', 'display_specific_shipping_class', 15 );
function display_specific_shipping_class(){
    global $product;

    // HERE define your targeted shipping class name
    $defined_shipping_class = "Estimated Delivery in 7-15 days";

    $product_shipping_class = $product->get_shipping_class();

    // Get the product shipping class term name
    $term_name = get_term_by( 'slug', $product_shipping_class, 'product_shipping_class' );

    if( $term_name == $defined_shipping_class ){
        echo '<p class="product-shipping-class">' . $term_name . '</p>';
    }
}

1 个答案:

答案 0 :(得分:1)

您得到的是SELECT array_to_json(array_agg("LocationClasses" ORDER BY Location)) AS "FullSchedule" FROM ( SELECT location, json_build_object('location', location, 'days', array_to_json(array_agg("LocationDayClasses" ORDER BY day))) AS "LocationClasses" FROM ( SELECT location, day, json_build_object('day', day, 'classes', array_to_json(array_agg(json_build_object('title', title, 'teacher', teacher,'starts', "startTime", 'ends', "endTime", 'cancelled', canceled) ORDER BY "startTime"))) as "LocationDayClasses" FROM "Schedules" GROUP BY location, day ) T1 GROUP BY location ) T2 对象,而不是术语名称。因此,请使用以下内容:

WP_term

代码进入您的活动子主题(或活动主题)的function.php文件中。现在应该可以使用了。

相关问题