我正在嘗試構建一個插件,當我認為它不應該存在時,我就陷入了這個奇怪的致命錯誤。
add_action( 'wp_head', 'my_custom_plugin' );
function my_custom_plugin() {
global $product;
if (is_product()) {
$product_type = $product->get_type();
if ($product_type =='variable') {
...things happening here....
}
}
}
我的檔案中也包含此代碼 require_once ($_SERVER['DOCUMENT_ROOT'].'/wp-load.php');
謝謝你 :)
uj5u.com熱心網友回復:
不確定到底發生了什么,但你可以試試這個代碼,看看它是否適合你。它適用于我:
add_action( 'wp_head', 'my_custom_plugin' );
function my_custom_plugin()
{
global $post;
if (is_product()) {
$product = wc_get_product($post->ID);
$product_type = $product->get_type();
if($product_type == 'variable'){
// ...things happening here....
}
}
}
讓我知道它是否有效!
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/342804.html
標籤:php WordPress的 求购 插件
下一篇:獲取與分類法關聯的用戶串列
