在添加到购物车上显示自定义文本点击/点击WooCommerce
问题描述:
我试图显示一个自定义文本'如果您今天结帐,您的产品将在星期日发送'(最好是作为工具提示)当我的用户点击在Woo上添加到购物车按钮。我如何去做。任何我重复使用的示例代码?在添加到购物车上显示自定义文本点击/点击WooCommerce
答
转到woocommerce模板single-product\add-to-cart
的以下目录。然后在这个目录下的每个php
文件中搜索add_to_cart_button
。您将找到相关的html标签来添加自定义工具提示。谈话后
更新答案:
/**
* Custom Add To Cart Messages
* Add this to your theme functions.php file
**/
add_filter('wc_add_to_cart_message_html', 'woocommrece_custom_add_to_cart_message');
function woocommrece_custom_add_to_cart_message() {
global $woocommerce;
$twoDayFromNow = date('l' , strtotime('tomorrow + 1day'));
$messageContent = 'Your product will be delivered by ' . $twoDayFromNow . ' if you checkout today';
// Output success messages
if (get_option('woocommerce_cart_redirect_after_add')=='yes') :
$return_to = get_permalink(wc_get_page_id('shop'));// Give the url, you want to redirect
$message = sprintf('<a href="%s">%s</a> %s', $return_to, __('Continue Shopping →', 'woocommerce'), __($messageContent, 'woocommerce'));
else :
$message = sprintf('<a href="%s">%s</a> %s', get_permalink(wc_get_page_id('cart')), __('View Cart →', 'woocommerce'), __($messageContent, 'woocommerce'));
endif;
return $message;
}
/* Custom Add To Cart Messages */
是在添加到购物车目录中,你会发现'variable.php'&'grouped.php'文件。请检查目录。 – gvgvgvijayan
找到此行。我在这里编辑什么?抱歉!不是编码器。只是想完成一些事情。感谢您对我的耐心:) –
您使用的代码片段来自用户查看简单产品页面时显示的文件'simple.php'。 ''。你见过在html标签'button'中添加属性'title'吗?现在,如果用户将鼠标悬停在“添加到购物车”按钮上,标题将显示为工具提示。 – gvgvgvijayan