wordpress - 编辑可变产品的“添加到购物车”按钮
问题描述
我的网站中有此代码的三个版本,用于生产 3 个按钮(1x 数量、3x 数量和 10x 数量)。我的产品是可变的。直到我删除了这一行代码才起作用if( ! $product->is_type('simple') ) return;
。删除此行后,是否应将其替换为可变产品的其他内容以确保代码正确完整?
add_action( 'woocommerce_after_add_to_cart_button', 'additional_simple_add_to_cart_10', 20 );
function additional_simple_add_to_cart_10() {
global $product;
// Only for simple product type
if( ! $product->is_type('simple') ) return; // Removed this line
$href = '?add-to-cart=' . esc_attr( $product->get_id() ) . '&quantity=10';
$class = 'ingle_add_to_cart_button-10 button alt';
$style = 'display: inline-block; margin-top: 12px;';
$button_text = __( "10 Tickets", "woocommerce" );
// Output
echo '<br><a rel="no-follow" href="'.$href.'" class="'.$class.'" style="'.$style.'">'.$button_text.'</a>';
}
// Redirect to checkout after add to basket
add_filter( 'woocommerce_add_to_cart_redirect', 'misha_skip_cart_redirect_checkout' );
function misha_skip_cart_redirect_checkout( $url ) {
return wc_get_checkout_url();
}
解决方案
推荐阅读
- uber-api - Uber API“此端点至少需要以下范围之一:partner.payments、partner.payments.internal_driver_id”
- assembly - 汇编器 - 将两个大的十六进制数相乘
- java - 将 For-Each-Loop 中来自 Retrofit2 调用的服务器响应保存到文件、数据库或新 List / ArrayList
- java - MediaPlayer - onCompletion 问题
- flutter - 在 webrtc 视频通话中响铃(颤振 webrtc)
- javascript - 取决于 URL 的条件渲染
- python - Pygame 告诉我图像不是文件对象
- firebase - 允许谷歌云计算访问firestore
- google-cloud-platform - GCP Terraform - 在没有 sudo 的情况下导入 ssh-keys
- c# - 项目出现延迟