我正在嘗試將自定義屬性添加到 WooCommerce 購物車中的產品標簽這就是我正在使用的
add_filter( 'woocommerce_cart_item_name', 'woo_api_cart_item_name', 10, 3 );
function woo_api_cart_item_name($item_name, $cart_item, $cart_item_key){
(... some code)
if($status == "NEW"){
if(isset($cart_item["clientDesignURL"]))
{
$item_name.= " <span style='color:red;' >?</span> <a style='color:white;' href='".$cart_item["clientDesignURL"]."' class='clientDesignURLButton'> Customize</a>";
}
else
{
$item_name.= "<p onclick='myCustomFunctionB()' class='clientDesignURLError'>-</p>";
}
}
else{
$item_name .= "<span onclick='myCustomFunctionA()' style='color:green;' class='".$cart_item["clientDesignID"]."'>? <img src='".$decoded_response->thumbUrl."'/></span>";
}
return $item_name;
}
我正在嘗試在購物車中在 ajax 中執行某些操作的每個專案旁邊添加按鈕。問題是 woocommerce / wordpress 洗掉了“onclick”屬性。
我嘗試了其他標簽,但所有標簽都被洗掉了。瀏覽器檢查器 更改主題不起作用。我檢查了所有插件,它也沒有作業。嘗試其他標簽,如
不起作用(整個標簽被洗掉)
uj5u.com熱心網友回復:
add_filter( 'wp_kses_allowed_html', 'prefix_filter_allowed_html', 10, 2 );
/**
* Add "onclick" to allowed KSES output.
*
* @param $allowed
* @param $context
* @return mixed
*/
function prefix_filter_allowed_html( $allowed, $context ) {
if ( 'post' === $context ) {
$allowed['p']['onclick'] = true;
}
return $allowed;
}
將 onclick 屬性添加到允許的 HTML<p>標記
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/466610.html
標籤:php WordPress woocommerce 大车 钩woocommerce
