WordPress教程:WooCommerce自定义添加到购物车消息

经过 小朱笔记 | 3 月 17, 2019 | WordPress技巧 | 0条评论

自定义添加到购物车消息

/**
 * Custom Add To Cart Messages
 * Add this to your theme functions.php file
 **/
add_filter( 'woocommerce_add_to_cart_message', 'custom_add_to_cart_message' );
function custom_add_to_cart_message() {
  global $woocommerce;
 
  https:// Output success messages
  if (get_option('woocommerce_cart_redirect_after_add')=='yes') :
 
    $return_to  = get_permalink(woocommerce_get_page_id('shop'));
 
    $message    = sprintf('<a href="%s" class="button">%s</a> %s', $return_to, __('Continue Shopping →', 'woocommerce'), __('Product successfully added to your cart.', 'woocommerce') );
 
  else :
 
    $message    = sprintf('<a href="%s" class="button">%s</a> %s', get_permalink(woocommerce_get_page_id('cart')), __('View Cart →', 'woocommerce'), __('Product successfully added to your cart.', 'woocommerce') );
 
  endif;
 
    return $message;
}

在哪里添加此代码?

将PHP代码放在主题或子主题functions.php文件的底部。

0条评论

提交评论

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理