我需要添加两种不同的运费,具体取决于购买用户的角色。我的角色是“wholesale_customer”,不应支付运费。但是,如果购物车小计等于或小于 \xe2\x82\xac90,则必须阻止购买并在结账时添加一条消息。(记住一定要达到\xe2\x82\xac90的数量)
\n另一个选项是所有其他 WordPress 角色,如果他们的购物车小计为 \xe2\x82\xac40 或更少,则需要支付 \xe2\x82\xac5 运费。
\n我已在 WooCommerce 中配置了送货,我创建了两种具有最低订单金额的免费送货方式,一种为 \xe2\x82\xac40,另一种为 \xe2\x82\xac90。
\n问题是,具有“wholesale_customer”角色的用户在达到 \xe2\x82\xac40 的金额时,也启用了该免费送货方法,但这种情况不应该发生,因为对于此用户角色(\' Wholesale_customer \' ) 如果购买量超过 \xe2\x82\xac90 的最小值,则免运费。
\n我已按以下方式在 WooCommerce 中配置发货,创建 2 种发货方式:\n- 其中一种在 \xe2\x82\xac90 处具有“所需的最小数量”
\n另一个在 \xe2\x82\xac40 处具有“所需的最小数量”
\n以及其中一份运费为 \xe2\x82\xac0。
\n我尝试添加以下功能来添加以获得我需要的内容,但所有运输方式始终处于启用状态,因此也为用户激活了“最小 \xe2\x82\xac40 免费送货”的零售运输方式具有批发客户角色的情况不应发生这种情况,因为具有此角色的用户将受益于不属于他们的好处。
\n我正在展示一些我用来尝试做我正在寻找的事情的代码,因为我做了很多测试。只是我还没有办法添加我在演示文稿中提到的角色“wholesale_customer\”的文本\n显示 WooCommerce 设置的图像
\nfunction custom_shipping_methods_visibility( $available_methods ) {\n \n $subtotal = WC()->cart->subtotal;\n \n $user = wp_get_current_user();\n $user_roles = $user->roles;\n \n // Check user role and cart subtotal to …
Run Code Online (Sandbox Code Playgroud) 我正在经营woocommerce商店,并使用统一费率送货$15
。我写了一个公式$1.25
为每个其他项目添加。
13.50 +(1.25 * [数量])
$1.25
为附加的每个项目喝“统一费率设置| :
但是我想$1.25
每3个项目加上这个费用。我的意思是3、6、9、12,依此类推...
谁能告诉我该怎么做?任何帮助表示赞赏。
我正在尝试自定义WC Checkout页面。在结帐页面上,我设置了2种送货方式。我的目标是在第一种运输方式下添加一个自定义字段。为此,我使用了下面提到的钩子。
woocommerce_after_shipping_rate
Run Code Online (Sandbox Code Playgroud)
但是我的问题是,它只是为每种可用的运输方式添加了相同的字段。如何管理特定运输方式的输入字段?
我在使用默认的 WooCommerce 运输类别设置时遇到问题。我们有一个小型网上商店,运费为 2 美元。一种用于适合放入邮箱的产品,另一种用于不适合放入邮箱的产品。
我们想设置一下,如果有2个产品具有邮箱运输级别,则价格变为套餐价格。
现在默认情况下,WooCommerce 仅收取邮箱运输等级的 1 倍费用。
(如何)我可以在 WooCommerce 中设置固定费用运费的 max_fee 吗?
将其添加到运输方式的固定费用设置中的成本字段中是有效的:
(1 * [qty]) + [fee min_fee = "2,5"]
Run Code Online (Sandbox Code Playgroud)
(即每个订单的运费 2,5 + 每个产品 1 欧元)-> 每个产品至少 3,5 并增加 + 1)。
但是,我想收取最低 3,50 美元(1 件商品)和最高 4,50 美元(2 件或更多商品)的费用。即在功能上这个公式:(3,5 * [qty])
或 [fee **max_fee** = "4,5"]
这可能吗?/ 使用的正确语法是什么?我在任何地方都找不到这个。我只找到了这个参考(“为统一费率添加 max_fee 短代码属性”/“除了统一费率成本字段中的 min_fee 之外还允许 max_fee”),这似乎表明对固定费用(百分比除外)的 max_fee 的功能请求已实施。但我无法让它发挥作用。
我实质上是在尝试复制购物车页面上的功能,用户可以在其中添加他们的商品zip code
,并计算可用的运费,但是我试图从后端在已经创建的订单中进行操作。
我找不到直接从WC_Order
实例执行此操作的方法,因此,我的下一个优点是清除购物车会话,将订单中的所有项目添加到购物车会话,然后尝试进行计算。
到目前为止,这就是我所拥有的。我一直坚持如何计算整个订单的价格。
$order_id = isset($_POST['order_id'])?$_POST['order_id']:0;
$country = isset($_POST['country'])?$_POST['country']:0;
$state = isset($_POST['state'])?$_POST['state']:0;
$postcode = isset($_POST['postcode'])?$_POST['postcode']:0;
$city = isset($_POST['city'])?$_POST['country']:0;
$order = wc_get_order( $order_id );
$order_items = $order->get_items();
// Don't know if this would save country of logged in user, or only create a temporary guest user session which is what I'd need
if ( $country != '' ) {
WC()->customer->set_billing_location( $country, $state, $postcode, $city );
WC()->customer->set_shipping_location( $country, $state, $postcode, $city );
} else {
WC()->customer->set_billing_address_to_base();
WC()->customer->set_shipping_address_to_base(); …
Run Code Online (Sandbox Code Playgroud) 我在应用程序中的实现就像我的 WooCommerce 网站一样。我想在计算运费时实现以下几点:
到目前为止,我实现的是第 4 点。我能够通过网站计算所有运输方式,但如果不是通过网站计算,那么它会在那里返回 null。
这是我的 API 代码:
function register_get_cart_shipping() {
register_rest_route(
'custom-plugin', '/getCartShipping/',
array(
'methods' => ['GET'],
'callback' => 'getCartShipping',
)
);
function getCartShipping() {
$chosen_methods = WC()->session->get('chosen_shipping_methods');
$count = 0;
foreach( WC()->session->get('shipping_for_package_0')['rates'] as $method_id => $rate ){
$data[$count]->rate_id = $rate->id;
$data[$count]->method_id = $rate->method_id;
$data[$count]->instance_id = $rate->instance_id;
$data[$count]->label = $rate->label;
$data[$count]->cost = $rate->cost;
$data[$count]->taxes = $rate->taxes;
$data[$count]->chosen = $chosen_methods['rate_id'];
if($chosen_methods['rate_id'] == $rate->id ){
$data[$count]->isSelected = true;
} else {
$data[$count]->isSelected = false; …
Run Code Online (Sandbox Code Playgroud) php android woocommerce woocommerce-rest-api shipping-method
我正在使用 WooCommerce 在 Wordpress 上开发电子商务网站。我想在订单确认页面(即付款后)检索并显示客户在结账时选择的“运输方式”(即交付或收集等)。
我正在尝试使用get_post_meta($post_id, $key, $single)
函数来做到这一点。我无法这样做,因为我不知道 $key 值。
我尝试了以下代码(在 php 标签内):
echo get_post_meta( $order_id, 'shipping_method', true );
Run Code Online (Sandbox Code Playgroud)
但它返回一个空白值(页面上没有显示)。我假设我使用的是不正确的$key
.
我愿意接受使用其他(更简单的)方法来实现这一目标的建议。
我刚刚实施了自定义运输解决方案。
这取决于购物车中商品的总价。例如:
if total is < 20 -> display free shipping
if total is >= 20 -> paid delivery
Run Code Online (Sandbox Code Playgroud)
但是我有 woocommerce 缓存的问题......我认为事实是 woocommerce 缓存了运费,而不是考虑订单数量的变化。那么问题出在calculate_shipping_for_package()方法上吗?
如果我启用运输调试模式,一切正常,没有任何更新。
我试图禁用缓存,但没有成功。
add_action('woocommerce_checkout_update_order_review', function() {
$packages = WC()->cart->get_shipping_packages();
foreach ($packages as $key => $value) {
$shipping_session = "shipping_for_package_$key";
unset(WC()->session->$shipping_session);
}
}, 10, 2);
Run Code Online (Sandbox Code Playgroud)
所以。你遇到过这样的问题吗?你是怎么解决的?非常感谢您的帮助!
在includes
子文件夹上的 Woocommerce 插件中,有一个文件wc-cart-functions.php
.
我想更改函数wc_cart_totals_shipping_method_label()
,但不允许将函数复制到我的主题的functions.php。我相信我必须使用自定义操作/过滤器来更改此核心功能,但不知道该怎么做。
原函数:
function wc_cart_totals_shipping_method_label( $method ) {
$label = $method->get_label();
$has_cost = 0 < $method->cost;
$hide_cost = ! $has_cost && in_array( $method->get_method_id(), array( 'free_shipping', 'local_pickup' ), true );
if ( $has_cost && ! $hide_cost ) {
if ( WC()->cart->display_prices_including_tax() ) {
$label .= ': ' . wc_price( $method->cost + $method->get_shipping_tax() );
if ( $method->get_shipping_tax() > 0 && ! wc_prices_include_tax() ) {
$label .= ' <small class="tax_label">' . WC()->countries->inc_tax_or_vat() . '</small>';
} …
Run Code Online (Sandbox Code Playgroud) php ×10
shipping-method ×10
woocommerce ×10
wordpress ×9
cart ×4
orders ×2
ajax ×1
android ×1
user-roles ×1