自己定义Woocommerce的产品属性(attributes)的短代码, 灵活应用到有需要的地方.
Step1-打开文件
Appearance>>Theme File Editor>>functions.php
Step2-添加代码
if ( ! function_exists( ‘display_product_additional_information’ ) ) {
function display_product_additional_information($atts) {
// Shortcode attribute (or argument)
$atts = shortcode_atts( array(
‘id’ => ”
), $atts, ‘product_additional_information’ );
// If the “id” argument is not defined, we try to get the post Id
if ( ! ( ! empty($atts[‘id’]) && $atts[‘id’] > 0 ) ) {
$atts[‘id’] = get_the_id();
}
// We check that the “id” argument is a product id
if ( get_post_type($atts[‘id’]) === ‘product’ ) {
$product = wc_get_product($atts[‘id’]);
}
// If not we exit
else {
return;
}
ob_start(); // Start buffering
do_action( ‘woocommerce_product_additional_information’, $product );
return ob_get_clean(); // Return the buffered outpout
}
add_shortcode(‘product_additional_information’, ‘display_product_additional_information’);
Step3-使用代码[custom_product_description]
在Divi主题的模块化编辑器里使用代码, 在你想插入代码的地方>>添加module>>CODE>>填入[product_additional_information]
0条评论