与此类似但不完全。
我有一个可变订阅产品,可以分 12 个月分期付款。
如果“分期付款次数”为“全额付款”,我希望能够更改 1 个月的 £xxx 文本:
然后将接下来的 11 期付款按 2 个月/3 个月等方式进行。
我知道此代码只会显示价格,但我似乎无法修改它以仅更改 1 个月(全额付款选项):
add_filter('woocommerce_subscriptions_product_price_string_inclusions', 'remove_subscription_inclusions', 10, 2);
function remove_subscription_inclusions( $include, $product ) {
$include['subscription_length'] = '';
$include['subscription_period'] = '';
return $include;
}
我确实尝试过这个但没有任何效果:
add_filter('woocommerce_subscriptions_product_price_string_inclusions', 'custom_subscription_price_string_inclusions', 10, 2);
function custom_subscription_price_string_inclusions( $include, $product ) {
// Check if the product is a subscription product
if ($product->is_type('subscription')) {
// Get the variations of the subscription product
$variations = $product->get_available_variations();
// Loop through each variation to check for the 1-month payment option
foreach ($variations as $variation) {
// Get the variation's price and subscription length/period
$regular_price = $variation['display_price'];
$subscription_length = isset($variation['attributes']['pa_subscription_length']) ? $variation['attributes']['pa_subscription_length'] : '';
$subscription_period = isset($variation['attributes']['pa_subscription_period']) ? $variation['attributes']['pa_subscription_period'] : '';
// Check if this variation is the 1 month (single payment) option
if ('1' === $subscription_length && 'month' === $subscription_period) {
// Modify the price string for the 1 month single payment option
$include['price_string'] = '£' . $regular_price . ' (Full payment for 1 month)';
// Remove subscription length and period to avoid duplication
$include['subscription_length'] = '';
$include['subscription_period'] = '';
}
}
}
return $include;
}