Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在价格下方的单个产品页面中显示特定的产品属性_Php_Wordpress_Woocommerce_Product_Custom Taxonomy - Fatal编程技术网

Php 在价格下方的单个产品页面中显示特定的产品属性

Php 在价格下方的单个产品页面中显示特定的产品属性,php,wordpress,woocommerce,product,custom-taxonomy,Php,Wordpress,Woocommerce,Product,Custom Taxonomy,在woocommerce中,如果一个特定的产品属性有一个值,那么我想在产品单一产品页面的价格下显示它对应的文本/值 如何检查特定产品属性是否有值? 如何获取特定的产品属性名称和值以在单个产品页面中显示?以下内容将仅在具有值的情况下,在单个产品页面的价格下显示特定的产品属性标签名称+值 这可以通过使用 您必须在函数中定义产品属性slug 钩子函数: add_action( 'woocommerce_single_product_summary', 'product_attribute_after_

在woocommerce中,如果一个特定的产品属性有一个值,那么我想在产品单一产品页面的价格下显示它对应的文本/值

如何检查特定产品属性是否有值?
如何获取特定的产品属性名称和值以在单个产品页面中显示?

以下内容将仅在具有值的情况下,在单个产品页面的价格下显示特定的产品属性标签名称+值

这可以通过使用

您必须在函数中定义产品属性slug

钩子函数:

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

    // HERE add your product attribute SLUG or taxonomy
    $attribute_slug = 'color';

    $taxonomy = strpos($url, 'blog') !== false ? $attribute_slug : 'pa_' . $attribute_slug;
    $attribute_name = get_taxonomy( $taxonomy )->labels->singular_name;
    $term_name = $product->get_attribute( $taxonomy ); // The value

    if( empty($term_name) ) return; // Exit if empty value

    // If not empty we display it
    $output  = '<div class="product-attribute '.$taxonomy.'"><p>';
    $output .= '<strong> '.$attribute_name.'</strong>: ';
    $output .= '<span> '.$term_name.'</span>';
    echo $output . '</p></div>';
}
add_action('woocommerce_single_product_summary'、'product_attribute_后加_price',15);
价格(){
全球$产品;
//在这里添加产品属性SLUG或分类法
$attribute_slug='color';
$taxonomy=strpos($url,'blog')!==false?$attribute\u slug:'pa\u'.$attribute\u slug;
$attribute\u name=get\u taxonomy($taxonomy)->labels->singular\u name;
$term_name=$product->get_属性($taxonomy);//值
if(empty($term_name))return;//如果值为空则退出
//如果不是空的,则显示它
$output='';
$output.=''.$attribute_name.:';
$output.=''.$term_name';
echo$output.“

”; }

代码进入活动子主题(或活动主题)的function.php文件。测试和工作。

但我如何定义显示此内容的位置?我的单一产品页面上没有价格。我如何在吴画廊下方展示它?谢谢对不起,这不是我的帖子,所以我不能接受答案。但我现在确实提出了我自己的问题。谢谢