在Woocommerce 3.0中,单个变体添加到购物车按钮包含在容器div中:
<div class="woocommerce-variation-add-to-cart variations_button">
// do_actions for before and after add_to_cart_quantity
</div>
我想过滤html以删除容器div,而不会覆盖variation-add-to-cart-button.php模板文件而不使用jquery / javascript。
任何帮助都会很棒!
答案 0 :(得分:0)
请尝试以下代码。我没有测试过,但它应该有效。请先在你的开发环境中试试这个。
add_action( 'woocommerce_before_template_part', function( $template_name ) {
if ( 'single-product/add-to-cart/variation-add-to-cart-button.php' === $template_name ) {
ob_start();
}
} );
add_action( 'woocommerce_after_template_part', function( $template_name ) {
if ( 'single-product/add-to-cart/variation-add-to-cart-button.php' === $template_name ) {
$content = ob_get_clean();
$content = str_replace( '<div class="woocommerce-variation-add-to-cart variations_button">', '', $content );
$content = str_replace( '</div>', '', $content );
echo $content;
}
} );