Php 使用Wordpress自定义字段隐藏特定页面的WooCommerce产品元(SKU、类别、标记)
您可能还会问:如何使用WordPress自定义字段触发/定义WooCommerce操作/函数 使用WooCommerce和Wordpress,我已经完成了一个系统,通过该系统,我可以删除产品元,但只能删除某些产品页面上的产品元,我需要定义哪些页面将使用Wordpress自定义字段隐藏其产品元我要调用的自定义字段名:'hide\u product\u meta',定义的值必须为“1”或“0”,表示是或否 待隐藏:Php 使用Wordpress自定义字段隐藏特定页面的WooCommerce产品元(SKU、类别、标记),php,wordpress,woocommerce,custom-fields,Php,Wordpress,Woocommerce,Custom Fields,您可能还会问:如何使用WordPress自定义字段触发/定义WooCommerce操作/函数 使用WooCommerce和Wordpress,我已经完成了一个系统,通过该系统,我可以删除产品元,但只能删除某些产品页面上的产品元,我需要定义哪些页面将使用Wordpress自定义字段隐藏其产品元我要调用的自定义字段名:'hide\u product\u meta',定义的值必须为“1”或“0”,表示是或否 待隐藏: 我首先尝试创建一个过滤器来完成这项工作。此后,我编辑了这篇文章,将拉克希曼·拉吉普
我首先尝试创建一个过滤器来完成这项工作。此后,我编辑了这篇文章,将拉克希曼·拉吉普特在下面评论的建议包括在内 这段代码使用一个名为“hide_product_meta”的预先创建的自定义字段在页面上隐藏产品meta,您可以手动添加该字段。在自定义字段中定义一个“1”以触发代码,或定义任何其他内容以将其关闭:
/* WooCommerce hide product page meta - hide_product_meta */
function hide_product_page_meta() {
global $post;
$product_id = $post->ID;
$HideProductMetaValue = get_post_meta($product_id,'hide_product_meta',true);
if (strpos($HideProductMetaValue, '1') !== false) {
return remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );
remove_action( 'woocommerce_after_single_product_summary', 'action_woocommerce_after_single_product_summary', 10, 2 );
}
}
add_action('woocommerce_single_product_summary','hide_product_page_meta');
谢谢。在lakshman rajput的帮助下,我使用以下代码成功地使其工作,但我可以用“1”定义操作,而不是用“是”或“否”,如下所示:
/* WooCommerce hide product page meta - hide_product_meta */
function hide_product_page_meta() {
global $post;
$product_id = $post->ID;
$HideProductMetaValue = get_post_meta($product_id,'hide_product_meta',true);
if (strpos($HideProductMetaValue, '1') !== false) {
return remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );
remove_action( 'woocommerce_after_single_product_summary', 'action_woocommerce_after_single_product_summary', 10, 2 );
}
}
add_action('woocommerce_single_product_summary','hide_product_page_meta');
如果有人能在这个问题上进一步帮助我,我将不胜感激。