在我的帐户页面中更改 woocommerce 订阅 "shop" link
Change woocommerce subscription "shop" link inside my account page
我是编码方面的新手,目前正在使用 woocommerce 订阅插件,如果我没有任何订阅,我想更改默认值 "shop"。我希望它 link 到特定产品而不是商店。
我要修改红色部分:
以下是该部分的当前代码:
<?php
// translators: placeholders are opening and closing link tags to take to the shop page
printf( esc_html__( 'Anda masih belum melanggan. Mula melanggan %sdi sini%s.', 'woocommerce-subscriptions' ), '<a href="' . esc_url( apply_filters( 'woocommerce_subscriptions_message_store_url', get_permalink( wc_get_page_id( 'shop' ) ) ) ) . '">', '</a>' );
?>
</p>
<?php endif; ?>
我想将 example.com/shop
更改为 example.com/product-category/myproduct
我们将不胜感激。
为此,您需要:
- 检测当前用户是否有有效订阅的条件函数
- 挂钩在
woocommerce_subscriptions_message_store_url
过滤器挂钩中的自定义函数,其中 您将定义链接到您的产品的新 URL 。
代码如下:
// Conditional function detecting if the current user has an active subscription
function has_active_subscription( $user_id=null ) {
// if the user_id is not set in function argument we get the current user ID
if( null == $user_id )
$user_id = get_current_user_id();
// Get all active subscrptions for a user ID
$active_subscriptions = get_posts( array(
'numberposts' => -1,
'meta_key' => '_customer_user',
'meta_value' => $user_id,
'post_type' => 'shop_subscription', // Subscription post type
'post_status' => 'wc-active', // Active subscription
) );
// if user has an active subscription
if( ! empty( $active_subscriptions ) ) return true;
else return false;
}
// Change woocommerce subscription “shop” link inside my account page
add_filter( 'woocommerce_subscriptions_message_store_url', 'custom_subscriptions_message_store_url', 10, 1 );
function custom_subscriptions_message_store_url( $url ){
// If current user has NO active subscriptions
if( ! has_active_subscription() ){
// HERE Define below the new URL linked to your product.
$url = home_url( "/product-category/myproduct/" );
}
return $url;
}
此代码位于您的活动子主题(或主题)的 function.php 文件或任何插件文件中。
已测试并有效
我是编码方面的新手,目前正在使用 woocommerce 订阅插件,如果我没有任何订阅,我想更改默认值 "shop"。我希望它 link 到特定产品而不是商店。
我要修改红色部分:
以下是该部分的当前代码:
<?php
// translators: placeholders are opening and closing link tags to take to the shop page
printf( esc_html__( 'Anda masih belum melanggan. Mula melanggan %sdi sini%s.', 'woocommerce-subscriptions' ), '<a href="' . esc_url( apply_filters( 'woocommerce_subscriptions_message_store_url', get_permalink( wc_get_page_id( 'shop' ) ) ) ) . '">', '</a>' );
?>
</p>
<?php endif; ?>
我想将 example.com/shop
更改为 example.com/product-category/myproduct
我们将不胜感激。
为此,您需要:
- 检测当前用户是否有有效订阅的条件函数
- 挂钩在
woocommerce_subscriptions_message_store_url
过滤器挂钩中的自定义函数,其中 您将定义链接到您的产品的新 URL 。
代码如下:
// Conditional function detecting if the current user has an active subscription
function has_active_subscription( $user_id=null ) {
// if the user_id is not set in function argument we get the current user ID
if( null == $user_id )
$user_id = get_current_user_id();
// Get all active subscrptions for a user ID
$active_subscriptions = get_posts( array(
'numberposts' => -1,
'meta_key' => '_customer_user',
'meta_value' => $user_id,
'post_type' => 'shop_subscription', // Subscription post type
'post_status' => 'wc-active', // Active subscription
) );
// if user has an active subscription
if( ! empty( $active_subscriptions ) ) return true;
else return false;
}
// Change woocommerce subscription “shop” link inside my account page
add_filter( 'woocommerce_subscriptions_message_store_url', 'custom_subscriptions_message_store_url', 10, 1 );
function custom_subscriptions_message_store_url( $url ){
// If current user has NO active subscriptions
if( ! has_active_subscription() ){
// HERE Define below the new URL linked to your product.
$url = home_url( "/product-category/myproduct/" );
}
return $url;
}
此代码位于您的活动子主题(或主题)的 function.php 文件或任何插件文件中。
已测试并有效