按照你的方法我建议wp_footer
同样,这样脚本将接近正文的末尾,这样它将在加载所有DOM之后加载。
add_action(\'woocommerce_ajax_added_to_cart\', \'set_button_classes\');
function set_button_classes () {
add_action(\'wp_footer\', function () {
echo "<script>document.getElementByClassName(\'added_to_cart wc-forward\').classList.add(\'ct-cart-item\', \'ct-offcanvas-trigger\');</script>";
});
}
您还可以关闭php标记,然后在
wp_footer
anonymos功能使其更容易理解/查看临时代码
add_action(\'woocommerce_ajax_added_to_cart\', \'set_button_classes\');
function set_button_classes () {
add_action(\'wp_footer\', function () {
?>
<script>
document.getElementByClassName(\'added_to_cart wc-forward\').classList.add(\'ct-cart-item\', \'ct-offcanvas-trigger\');
</script>
<?php
});
}