doujiu5464 2016-06-28 09:25
浏览 65
已采纳

当购物车不为空时,设置购物车固定链接

I have no cart link set in the backend of WooCommerce. Instead I have the cart redirected to the checkout page. This works fine, however now I end up with empty urls. When I add a product to the cart I get the message 'successfully added to the cart, see the cart here'. 'See the cart here' is linked to wc_get_page_permalink( 'cart' ), but this is not set.

Is it possible through a function to set the wc_get_page_permalink( 'cart' ) ONLY when items are in the cart?

I tried something like:

function custom_continue_shopping_redirect_url ( $product_id ) {
    $url = "http://www.url.com"; // Add your link here
    return $url;
}
add_filter('wc_add_to_cart_message', 'custom_continue_shopping_redirect_url');

But that is obviously replacing the whole add to cart message.

Thanks.

  • 写回答

1条回答 默认 最新

  • dongyuan1902 2016-06-28 09:48
    关注

    You missed some code. try it this way:

    add_filter( 'wc_add_to_cart_message', 'custom_continue_shopping_redirect_url', 10, 2 );
    function custom_continue_shopping_redirect_url( $message, $product_id ) {
        global $woocommerce;
    
            // $permalink = get_permalink(woocommerce_get_page_id('shop')); // replaced by:
            $permalink = get_permalink(woocommerce_get_page_id('cart')); // your link here.
            $message    = sprintf('<a href="%s" class="button wc-forwards">%s</a> %s', $permalink, __('Continue Shopping', 'woocommerce'), __('Product successfully added to your cart.', 'woocommerce') );
        return $message;
    }
    

    You will have to fine tune your replacement link. You can also change the text…

    References:

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用