【发布时间】:2021-06-12 15:47:02
【问题描述】:
我使用WooCommerce Deposits 插件,如果客户选择支付押金,我想隐藏除“本地取货”运输方式之外的所有其他运输方式。
客户可以在产品页面上选择是支付例如 10% 的定金还是支付订单的全部金额。发货方式 flat_rate 用于发送订单(如果已全额付款),应隐藏,因为客户需要先支付剩余订单金额并在(线下)商店本地取货。
产品页面上的选择:
<input type="radio" name="wc_deposit_option" value="yes" id="wc-option-pay-deposit">
<input type="radio" name="wc_deposit_option" value="no" id="wc-option-pay-full" checked="checked">
我尝试将可用的隐藏运输方式代码 sn-ps 与 _wc_deposit_enabled 元数据结合起来,但我无法弄清楚。帮助将不胜感激。
/**
* Are deposits enabled for a specific product
* @param int $product_id
* @return bool
*/
public static function deposits_enabled( $product_id, $check_variations = true ) {
$product = wc_get_product( $product_id );
if ( ! $product || $product->is_type( array( 'grouped', 'external' ) ) ) {
return false;
}
$setting = get_post_meta( $product_id, '_wc_deposit_enabled', true );
if ( $check_variations && empty( $setting ) ) {
$children = get_children( array(
'post_parent' => $product_id,
'post_type' => 'product_variation',
) );
foreach ( $children as $child ) {
$child_enabled = get_post_meta( $child->ID, '_wc_deposit_enabled', true );
if ( $child_enabled ) {
$setting = $child_enabled;
break;
}
}
}
if ( empty( $setting ) ) {
$setting = get_option( 'wc_deposits_default_enabled', 'no' );
}
if ( 'optional' === $setting || 'forced' === $setting ) {
if ( 'plan' === self::get_deposit_type( $product_id ) && ! self::has_plans( $product_id ) ) {
return false;
}
return true;
}
return false;
}
【问题讨论】:
-
存款是客户可以选择的支付方式吗?客户如何以及在哪里选择使用押金付款?当购物车物品有押金或客户选择使用押金付款时,是否需要隐藏其他运输方式?你在使用插件吗?请尝试澄清您的问题,编辑它。
-
谢谢,我已经编辑了这个问题。我希望现在很清楚。
-
是的,清楚并回答了。请对以下答案提供一些反馈。
标签: php wordpress woocommerce plugins shipping-method