【问题标题】:Display a coupon code on single product pages in Woocommerce在 Woocommerce 的单个产品页面上显示优惠券代码
【发布时间】:2018-11-25 13:30:06
【问题描述】:

我想在 woocommerce 的每个产品页面上显示折扣券,原因有两个。

  1. 尽管我的本意是好的,但许多新客户忽略了主页和网站标题中提到的折扣券。

  2. 我想通过折扣券鼓励更多用户进行预付付款并避免货到付款。

这有可能实现吗?

【问题讨论】:

    标签: php wordpress woocommerce product coupon


    【解决方案1】:

    更新:添加了购物车页面的钩子……

    这可以通过以下方式简单地完成,这将在单个产品页面中添加带有优惠券代码的自定义通知消息:

    add_action( 'woocommerce_before_single_product', 'custom_message_before_single_product', 5 ); // For single product page
    add_action( 'woocommerce_before_cart', 'custom_message_before_single_product'); // For cart page
    function custom_message_before_single_product() {
        $coupon_code = 'special10';
    
        wc_print_notice( sprintf(
            __("You get %s when using credit card payment with the %s coupon code.", "woocommerce"),
            '<strong>' . __("a 10% discount", "woocommerce") . '</strong>',
            '<code>' . $coupon_code . '</code>'
        ), 'notice' );
    }
    

    代码进入您的活动子主题(或活动主题)的 function.php 文件中。经过测试并且有效。

    你会在你的单个产品页面中得到类似的东西:

    【讨论】:

    • 很抱歉再次打扰您,但我想知道相同的消息是否也可以显示在购物车页面中?
    猜你喜欢
    • 2018-05-17
    • 2014-11-26
    • 2023-02-01
    • 2014-09-08
    • 2020-03-19
    • 2016-02-25
    • 2019-02-17
    • 2017-12-29
    • 2012-09-11
    相关资源
    最近更新 更多