对于php–Woocommerce从外部来源更新价格感兴趣的读者,本文将会是一篇不错的选择,并为您提供关于php–WooCommerce3主要更新模板错误、php–Woocommerce–如何从外部脚
对于php – Woocommerce从外部来源更新价格感兴趣的读者,本文将会是一篇不错的选择,并为您提供关于php – WooCommerce 3主要更新模板错误、php – Woocommerce – 如何从外部脚本添加产品变体、php – WooCommerce – 显示价格包含产品页面的税、php – Woocommerce从Checkout页面删除优惠券部分的有用信息。
本文目录一览:- php – Woocommerce从外部来源更新价格
- php – WooCommerce 3主要更新模板错误
- php – Woocommerce – 如何从外部脚本添加产品变体
- php – WooCommerce – 显示价格包含产品页面的税
- php – Woocommerce从Checkout页面删除优惠券部分
php – Woocommerce从外部来源更新价格
function chd_the_post_action( $post ) { if ( $post && $post->post_type == 'product' ) { $product = wc_get_product( $post->ID ); if ( $product ) { $price = '1718'; $product->set_price( "$price" ); $product->set_regular_price( "$price" ); $product->set_sale_price( "$price" ); $product->save(); } } }
此代码更新了数据库中的产品价格,但它不会在同一时刻更改页面上的价格视图,而是仅在页面重新加载后,因为post和product变量是由setup_postdata()设置的.
因此我使用woocommerce钩子显示更新价格:
function chd_get_price_filter( $price,$item ) { return '1718'; } add_filter( 'woocommerce_product_get_price','chd_get_price_filter',100,2 ); add_filter( 'woocommerce_product_get_regular_price',2 ); add_filter( 'woocommerce_product_get_sale_price',2 );
有没有可以用更好的方式做这个动作的钩子?
解决方法
update_post_Meta( $product->id,'_sale_price','1718' ); update_post_Meta( $product->id,'_regular_price','1718 );
php – WooCommerce 3主要更新模板错误
上周我更新到PHP 7,我也将WooCommerce更新到3.0.x.
但是在更新之后我注意到我在用户注册中的额外字段不再起作用了.我使用WP-Member插件添加了那些额外的字段.
当我进一步搜索页面底部的WooCommerce系统状态时,我发现了这个错误
customtheme/woocommerce/cart/cart.PHP version 2.1.0 is out of date.
The core version is 3.0.0,
customtheme/woocommerce/checkout/form-checkout.PHP version 2.0.0 is
out of date. The core version is 2.3.0,
customtheme/woocommerce/checkout/review-order.PHP version 2.1.8 is out
of date. The core version is 2.3.0,
customtheme/woocommerce/checkout/thankyou.PHP version 2.2.0 is out of
date. The core version is 3.0.0,
customtheme/woocommerce/content-product.PHP version 1.6.4 is out of
date. The core version is 3.0.0,
customtheme/woocommerce/loop/loop-start.PHP,
customtheme/woocommerce/loop/pagination.PHP,
customtheme/woocommerce/myaccount/form-edit-address.PHP version 2.1.0
is out of date. The core version is 2.6.0,
customtheme/woocommerce/single-product/add-to-cart/variable.PHP
version 2.1.0 is out of date. The core version is 2.5.0,
customtheme/woocommerce/single-product/product-image.PHP version
2.0.14 is out of date. The core version is 3.0.0, customtheme/woocommerce/single-product/product-thumbnails.PHP version
2.0.3 is out of date. The core version is 3.0.0, customtheme/woocommerce/single-product/short-description.PHP,
customtheme/woocommerce/single-product/tabs/description.PHP,
customtheme/woocommerce/single-product/title.PHP
任何人都可以帮我修复这些并使我的用户注册页面出现在我的所有自定义字段中
谢谢
解决方法:
WooCommerce 3.0+ is a really major update and is much more strict than before. A lot of things have changed and most of custom code used for WooCommerce version 2.6+ will need to be updated.
请参阅相关文章WooCommerce Development blog
在您的情况下,您需要更新位于customtheme(文件夹)中的主题中的所有woocommerce模板> woocommerce(子文件夹).
为此,您必须将所有列出的文件从woocommerce插件“templates”文件夹替换为您的主题woocommerce(子文件夹):
woocommerce/templates/cart/cart.PHP => customtheme/woocommerce/cart/cart.PHP
woocommerce/templates/checkout/form-checkout.PHP => customtheme/woocommerce/checkout/form-checkout.PHP
woocommerce/templates/checkout/review-order.PHP => customtheme/woocommerce/checkout/review-order.PHP
woocommerce/templates/checkout/thankyou.PHP => customtheme/woocommerce/checkout/thankyou.PHP
woocommerce/templates/content-product.PHP => customtheme/woocommerce/content-product.PHP
woocommerce/templates/loop/loop-start.PHP => customtheme/woocommerce/loop/loop-start.PHP
woocommerce/templates/loop/pagination.PHP => customtheme/woocommerce/loop/pagination.PHP
woocommerce/templates/myaccount/form-edit-address.PHP => customtheme/woocommerce/myaccount/form-edit-address.PHP
woocommerce/templates/single-product/add-to-cart/variable.PHP => customtheme/woocommerce/single-product/add-to-cart/variable.PHP
woocommerce/templates/single-product/product-image.PHP => customtheme/woocommerce/single-product/product-image.PHP
woocommerce/templates/single-product/product-thumbnails.PHP => customtheme/woocommerce/single-product/product-thumbnails.PHP
woocommerce/templates/single-product/short-description.PHP => customtheme/woocommerce/single-product/short-description.PHP
woocommerce/templates/single-product/tabs/description.PHP => customtheme/woocommerce/single-product/tabs/description.PHP
woocommerce/templates/single-product/title.PHP => customtheme/woocommerce/single-product/title.PHP
But keep a copy of that old template before, as you will need to replace in the new templates all changes that you have maid.
请参阅此相关文档:Template Structure + Overriding Templates via a Theme
php – Woocommerce – 如何从外部脚本添加产品变体
我有一个变量产品,其分类“pa_size”属性设置有以下值:S | M | L | XL
如何使用外部PHP脚本为该产品添加变体?
提前致谢.
我使用以下代码:
$sku = 21333;
$size = 'S';
$stock = 2;
$price_a = 60;
$price_b = 30;
$product_parent = get_product_by_sku($sku);
$product = new WC_Product_Variable($product_parent->id);
$variations = $product->get_available_variations();
// First off all delete all variations
foreach($variations as $prod_variation) {
$Metaid=MysqL_query("SELECT Meta_id FROM wp_postMeta WHERE post_id = ".$prod_variation['variation_id']);
while ($row = MysqL_fetch_assoc($Metaid)) {
MysqL_query("DELETE FROM wp_postMeta WHERE Meta_id = ".$row['Meta_id']);
}
MysqL_query("DELETE FROM wp_posts WHERE ID = ".$prod_variation['variation_id']);
}
// Now add new variation
$thevariation = array(
'post_title'=> '',
'post_name' => 'product-' . $product_parent->id . '-variation',
'post_status' => 'publish',
'post_parent' => $product_parent->id,
'post_type' => 'product_variation',
'guid'=>home_url() . '/?product_variation=product-' . $product_parent->id . '-variation'
);
$variation_id = wp_insert_post( $thevariation );
update_post_Meta($variation_id, 'post_title', 'Variation #' . $variation_id . ' of '. $product_parent->id);
wp_set_object_terms( $variation_id, $size, 'pa_size' );
update_post_Meta($variation_id, 'attribute_pa_size', $size);
update_post_Meta($variation_id, '_regular_price', $price_a);
update_post_Meta($variation_id, '_downloadable_files', '');
update_post_Meta($variation_id, '_download_expiry', '');
update_post_Meta($variation_id, '_download_limit', '');
update_post_Meta($variation_id, '_sale_price_dates_to', '');
update_post_Meta($variation_id, '_sale_price_dates_from', '');
update_post_Meta($variation_id, '_backorders', 'no');
update_post_Meta($variation_id, '_stock_status', 'instock');
update_post_Meta($variation_id, '_height', '');
update_post_Meta($variation_id, '_manage_stock', 'yes');
update_post_Meta($variation_id, '_width', '');
update_post_Meta($variation_id, '_sale_price_dates_from', '');
update_post_Meta($variation_id, '_backorders', 'no');
update_post_Meta($variation_id, '_stock_status', 'instock');
update_post_Meta($variation_id, '_manage_stock', 'yes');
update_post_Meta($variation_id, '_height', '');
update_post_Meta($variation_id, '_width', '');
update_post_Meta($variation_id, '_length', '');
update_post_Meta($variation_id, '_weight', '');
update_post_Meta($variation_id, '_downloadable', 'no');
update_post_Meta($variation_id, '_virtual', 'no');
update_post_Meta($variation_id, '_thumbnail_id', '0');
update_post_Meta($variation_id, '_sku', '');
update_post_Meta($variation_id, '_sale_price', $price_b);
update_post_Meta($variation_id, '_price', $price_b);
update_post_Meta($product_parent->id, '_min_variation_price', $price_b);
update_post_Meta($product_parent->id, '_max_variation_price', $price_b);
update_post_Meta($product_parent->id, '_min_price_variation_id', $variation_id);
update_post_Meta($product_parent->id, '_max_price_variation_id', $variation_id);
update_post_Meta($product_parent->id, '_min_variation_regular_price', $price_a);
update_post_Meta($product_parent->id, '_max_variation_regular_price', $price_a);
update_post_Meta($product_parent->id, '_min_regular_price_variation_id', $variation_id);
update_post_Meta($product_parent->id, '_max_regular_price_variation_id', $variation_id);
update_post_Meta($product_parent->id, '_min_variation_sale_price', $price_b);
update_post_Meta($product_parent->id, '_max_variation_sale_price', $price_b);
update_post_Meta($product_parent->id, '_min_sale_price_variation_id', $variation_id);
update_post_Meta($product_parent->id, '_max_sale_price_variation_id', $variation_id);
update_post_Meta($product_parent->id, '_price', $price_b);
update_post_Meta( $variation_id, '_stock', $stock );
update_post_Meta($product_parent->id, 'post_status', 'publish');
解决方法:
那么你可以在save_post上运行一个动作,以便在保存/更新帖子时做任何你想做的事情.或者在WooCommerce产品的情况下,您可以在他们的woocommerce_process_product_Meta钩子上运行它,该钩子在save_post上运行但已经有一些检查以确保它只适用于产品并且用户具有正确的权限等.使用他们的钩子,我们可以减少条件逻辑以检查产品是否是可变产品.如果是,请运行一些自定义代码.
add_action( 'woocommerce_process_product_Meta', 'so_27902470_update_variations', 10, 2 );
function so_27902470_update_variations( $post_id, $post ){
if( isset( $post['product_type'] ) && 'variable' == $post['product_type'] ){
// do your stuff
}
return $post_id;
}
php – WooCommerce – 显示价格包含产品页面的税
我列出的项目不包括增值税.
我需要在产品页面上单独显示价格,增值税和增值税(如结帐页面).
我找不到这样做的插件.
我怎样才能做到这一点?
从WooCommerce 3.0版开始,不推荐使用函数 woocommerce_price(),方法 get_price_including_tax()也是如此.您应该使用 wc_get_price_including_tax:
<?PHP echo wc_price( wc_get_price_including_tax( $product ) ); ?>
在WooCommerce v3.0.0之前
您需要修改模板.不要修改核心WooCommerce模板,而是使用WooCommerce模板覆盖系统将其复制到您的主题.有关这方面的帮助,请参阅使用template override system的WooCommerce文档.
在price.PHP模板中,您将在需要价格的地方添加这段代码,包括税(VAT):
<?PHP echo woocommerce_price( $product->get_price_including_tax() ); ?>
注意:您修改的price.PHP模板应位于wp-content / themes / [您的主题文件夹] /woocommerce/single-product/price.PHP中
php – Woocommerce从Checkout页面删除优惠券部分
我正在尝试删除位于Woocommerce结帐页面(/结帐)顶部的“有优惠券”部分.
我想将优惠券部分保留在购物车页面上,因此我无法完全禁用优惠券,但希望在结帐页面上将其删除.
任何帮助将不胜感激.
解决方法:
remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form', 10 );
把它放在你的functions.PHP中,这应该这样做.
我们今天的关于php – Woocommerce从外部来源更新价格的分享已经告一段落,感谢您的关注,如果您想了解更多关于php – WooCommerce 3主要更新模板错误、php – Woocommerce – 如何从外部脚本添加产品变体、php – WooCommerce – 显示价格包含产品页面的税、php – Woocommerce从Checkout页面删除优惠券部分的相关信息,请在本站查询。
本文标签: