我正在用WooCommerce订阅测试费用,并且注意到缺少一个支持无法帮助的功能。
当使用他们的示例代码(下面)向结帐添加“经常性费用”时,插件不会在收费价格之后添加订阅间隔。
示例:
实际:费用:£5.00
预期:费用:£5.00 /月
我第一次发现这个问题是通过使用Themecomplete的WooCommerce额外产品选项来增加一笔费用,然而,我注意到即使使用了WooCommerce插件开发指南中的代码,它也不适用于任何经常性的费用。
add_filter( 'woocommerce_cart_calculate_fees', 'add_recurring_postage_fees', 10, 1 );
function add_recurring_postage_fees( $cart ) {
if ( ! empty( $cart->recurring_cart_key ) ) {
$cart->add_fee( 'Postage', 5 );
}
}我可以在WooCommerce订阅中看到这个插件识别了经常性费用(file: recrency-极地s.php):
<?php foreach ( $recurring_cart->get_fees() as $recurring_fee ) : ?>
<tr class="fee recurring-total">
<th><?php echo esc_html( $recurring_fee->name ); ?></th>
<td><?php wc_cart_totals_fee_html( $recurring_fee ); ?></td>
</tr>
<?php endforeach; ?>开发人员指南:https://docs.woocommerce.com/document/subscriptions/develop/recurring-cart-fees/
从他们的截图中可以看出,在他们的例子中,“/month”这个词在费用中缺失了:Recurring Fees Image >
它需要基于订阅间隔的动态,而不仅仅是一个预先确定的短语。是否有人了解WooCommerce订阅和收费,以确定问题所在?
发布于 2020-05-14 10:23:45
add_filter( 'woocommerce_subscriptions_is_recurring_fee', '__return_true' );
add_filter( 'woocommerce_cart_calculate_fees', 'add_recurring_postage_fees', 10, 1 );
function add_recurring_postage_fees( $cart ) {
if ( !empty( $cart->recurring_cart_key ) ) {
$intervals = explode( '_', $cart->recurring_cart_key );
$cart->add_fee( 'Postage/' . end( $intervals ), 5, false, '' );
}
}

尝试将此作为一种可能的解决方案。
发布于 2020-05-14 15:23:56
而不是设置一个费用,我正在寻找的东西,与收费从任何来源,如其他插件。取代经常性费用价格线的东西会更好.(我知道这不管用,只是一个主意):
add_filter( 'woocommerce_cart_totals_fee_html', 'sab_custom_fee_interval' );
function sab_custom_fee_interval( $price ) {
return $price . $cart->recurring_cart_key;
}但我不知道$cart->recurring_cart_key在订阅插件中是如何工作的。还在玩这个..。
https://stackoverflow.com/questions/61770126
复制相似问题