我的网站上有两种产品,想要在将不同产品添加到购物车时显示不同的消息(在消息中我想使用 HTML)。现在它显示Product successfully added to cart.
我正在我孩子的 function.php 中使用此代码,该代码正在运行,但没有给我我真正想要的东西。
add_filter ( 'wc_add_to_cart_message', 'wc_add_to_cart_message_filter', 10, 2 );
function wc_add_to_cart_message_filter($message, $product_id = null) {
$titles[] = get_the_title( $product_id );
$titles = array_filter( $titles );
$added_text = sprintf( _n( '%s has been successfully added to your Basket.', '%s have been added to your Basket.', sizeof( $titles ), 'woocommerce' ), wc_format_list_of_items( $titles ) );
$message = sprintf( '%s <a href="%s" class="button">%s</a>',
esc_html( $added_text ),
esc_url( wc_get_page_permalink( 'cart' ) ),
esc_html__( 'View Cart', 'woocommerce' …
Run Code Online (Sandbox Code Playgroud) 在 Wordpress 中,我正在使用 Woocommerce v3.3.5 并在可变产品的单个产品页面中,当我单击添加到购物车按钮而我没有选择变体选项时,它会弹出一个警报,上面写着:
在将此产品添加到您的购物车之前,请选择一些产品选项。
到目前为止这是合乎逻辑的..
我的问题是如何将警报文本更改为其他内容以适合我的业务?
我有一个 php cron 作业,正在更新来自第 3 方供应商的产品信息。这些变化可以是价格、销售价格、库存等。
我的一切都在运行,除了当我通过以下代码销售产品时:
update_post_meta( $product_id, '_sale_price', $sale_price );
update_post_meta( $product_id, '_price', $sale_price );
Run Code Online (Sandbox Code Playgroud)
产品已正确更新,并在网站和产品管理上显示产品的销售价格。当我使用 woocommerce 的短代码之一来显示在售产品时,它不会撤回通过上述代码更新的内容,除非它是通过管理面板完成的。
[products limit="24" columns="4" on_sale="true" ]
Run Code Online (Sandbox Code Playgroud)
所以我的代码没有做 woocommerce 所做的事情,但我不知道我错过了什么。到目前为止,我发现的唯一解决方法是删除管理面板中的销售价格 - >保存,然后将其添加回来 - >并再次保存。由于 3,000 多种产品有 18,000 多种变体,这不是手工可以完成的事情。
顺便说一句:当我们导入 vis csv 文件源时,我也遇到了 WP all import 的问题。
任何想法或想法都会有帮助。
谢谢!
在单个产品页面中,我想更改选项卡中“附加信息”的位置,在使用 Woocommerce 挂钩(删除“附加信息”选项卡)添加到购物车按钮下。
我有:
add_action( 'woocommerce_product_additional_information', 'wc_display_product_attributes', 10 );
Run Code Online (Sandbox Code Playgroud)
和: woocommerce_after_add_to_cart_button
我想:
remove_action( 'woocommerce_product_additional_information', 'wc_display_product_attributes', 10 );
add_action( 'woocommerce_after_add_to_cart_button', 'woocommerce_product_additional_information' );
Run Code Online (Sandbox Code Playgroud)
和
remove_action( 'woocommerce_product_additional_information', 'wc_display_product_attributes', 10 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_product_additional_information', 60 );
Run Code Online (Sandbox Code Playgroud)
但它不起作用。
如何在添加到购物车按钮下方正确移动“附加信息”?
我使用此代码来显示产品库存:
add_action( 'woocommerce_after_shop_loop_item', 'display_variable_product_stock_quantity', 10 );
function display_variable_product_stock_quantity(){
wc_get_variable_product_stock_quantity( 'echo_html' );
}
function show_stock() {
global $product;
if ( $product->stock ) { // if manage stock is enabled
if ( ! $product->managing_stock() && ! $product->is_in_stock() )
echo '';
}
if ( number_format($product->stock,0,'','') > 0 ) { // if stock is low
echo '<div class="remainingpc" style="text-align:center;"><font color="red"> ' . number_format($product->stock,0,'','') . ' Pcs Left</font></div>';
}
else {
echo '<div class="remaining" style="text-align:center;"><font color="red">Out of Stock</font></div>';
}
}
add_action('woocommerce_after_shop_loop_item','show_stock', 10);
Run Code Online (Sandbox Code Playgroud)
如果产品是变量,我使用此答案代码来显示库存可用性:
在 Woocommerce …
有没有办法在 WordPress 仪表板中启用后端字段,以在存档页面和加售/相关产品中显示每个产品的自定义价格,但将价格保留在产品摘要中?
示例:产品 A 的价格为 10 欧元,但我想改为显示“6 欧元/公斤起”。
最简单的方法是使用一个自定义字段,该字段覆盖了 ,woocommerce_template_loop_price
但此代码不起作用,但我不明白为什么。
add_action('woocommerce_template_loop_price', 'shopprice_change', 10, 2);
function shopprice_change ($price, $product) {
global $post, $blog_id;
$post_id = $post->ID;
$price = get_post_meta($post_id, 'shoppricechange', true);
return $price;
wp_reset_query();
}
Run Code Online (Sandbox Code Playgroud)
更新
我找到了一种解决方案,可以在不更改单个产品页面的情况下更改存档页面中的价格:
function cw_change_product_html( $price_html, $product ) {
$unit_price = get_post_meta( $product->id, 'shoppricechange', true );
if (is_product()) return $price_html;
if ( ! empty( $unit_price ) ) {
$price_html = '<span class="amount">' . wc_price( $unit_price ) . '</span>';
}
return $price_html;
}
add_filter( 'woocommerce_get_price_html', …
Run Code Online (Sandbox Code Playgroud) 我有一个二维数组(矩阵),我试图计算相邻数字的最大乘积.它与Project Euler Problem 11非常相似,只是用户在计算中输入了他们想要的相邻数字.我觉得我没事.问题是如果我使用整数来计算5个整数99的乘积(例如99*99*99*99*99)它将无法正确显示.可以检查的相邻数字的最大数量是99.我已经尝试过更改为长双打(正如您在代码中看到的那样)但是它打印出荒谬的数字,例如我在所有矩阵位置输入99的3个相邻数字并且应该得到返回970299(我在maxProduct为int时执行),但我得到:
-497917511184158537131936752181264370659584929560826523880745083032965215342755650440802286656251727430041200624372430370294634536699364412350122489510814753628581807006780156992324264734484592980976635224618682514265787653963930812412392499329499188301075222828863209569131692032
Run Code Online (Sandbox Code Playgroud)
我觉得这是显而易见的,但我看不到它.
#include <stdio.h>
#include <stdlib.h>
long double calcProduct(int n, int m, int ** matrix)
{
int i, x, y; //Loop counters
long double maxProduct; //Used to hold the maximum product of numbers found so far
long double temp; //Used to hold the current product of numbers
//Searching left to right
for(y = 0; y < n; y++)
{
for(x = 0; x <= n - m; x++)
{
for(i = 0; i < m; …
Run Code Online (Sandbox Code Playgroud) 我已经使用此文档以编程方式创建了优惠券 -> https://docs.woocommerce.com/document/create-a-coupon-programatically/
效果很好,完成订单后生成一个动态优惠券代码。但我想只允许该订购产品的优惠券代码。
所以在上面的代码这里:
update_post_meta( $new_coupon_id, 'product_ids', '' );
我想使用该订单商品 ID 获取该订单产品 ID。
所以任何人都知道解决方案,然后请帮助我。
谢谢,凯坦。
我将通过推特推广我的产品联盟网站,我的活动是根据一些关键词得到所有推文(例如:红鞋).然后不好回复推文,如"请检查我的链接http://www.affliateexample.com/redshoe ".我有大量的推文数据,所以计划执行一个cron文件,通过我的推文应用程序(PHP)回复所有这些推文.这是一种正确的方式来完成这项工作,否则这将暂停我的推特账户.请告知这个......
我需要具有多个属性的Woocommerce单个产品,用户可以从每个属性中选择多个属性.例如,如果我设置属性颜色比用户获取颜色下拉菜单,用户可以选择多于1种颜色,如红色+黄色+绿色
如何为这个或任何插件定制woocommerce?
给定A和B的总和,让S i必须找到A*B的最大乘积,但是A的一个条件值将在[P,Q]的范围内.
怎么办呢?
如果没有范围,则任务非常简单.
使用推导方法.
如何找到最大产品,例如.
A + B = 99的A值将是[10,20]
那么A和B的最大乘积是多少
O(N)不足以解决问题