Woocommerce 3 过滤器单一变体添加到购物车按钮 html
Woocommerce 3 Filter Single Variation Add to cart button html
在 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.
任何帮助都会很棒!
请尝试以下代码。我还没有测试过,但它应该可以工作。请先在您的开发环境中尝试此操作。
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;
}
} );
在 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.
任何帮助都会很棒!
请尝试以下代码。我还没有测试过,但它应该可以工作。请先在您的开发环境中尝试此操作。
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;
}
} );