我有两个独立的电子商务平台。
到目前为止,我们已经成功地自动化了很多简单的事情,比如从 WP 拉订单,并将更新的库存水平推送给它。
然而,我无法理解的一件事是当我创建 free_shipping 方法并设置最低支出时。它存储在数据库中的什么位置?
我正在尝试为 WooCommerce 创建一个插件,根据产品重量计算运费。我不断收到此错误:
\n\n\n\n\n警告: WC_Your_Shipping_Method::calculate_shipping($package) 的声明应与 C:\\Users\\Michelle\\Dropbox\\MEDIEINSTITUTET\\Utveckling mot e-handel\\ 中的 WC_Shipping_Method::calculate_shipping($package = Array) 兼容WooCommerce\\WC-kurs\\wp-content\\plugins\\frakt\\frakt.php 第 18 行
\n
这是我的整个插件:
\n\n<?php \n/* *\n* Plugin Name: Min frakt modul\n Description: Ett plugin som ber\xc3\xa4knar frakt kostnad beroende p\xc3\xa5 vikten\n*/\n\n/**\n * Check if WooCommerce is active\n */\n\nif (!defined(\'ABSPATH\')) {\n exit;\n}\n\nif ( in_array( \'woocommerce/woocommerce.php\', apply_filters( \'active_plugins\', get_option( \'active_plugins\' ) ) ) ) {\n function your_shipping_method_init() {\n if ( ! class_exists( \'WC_Your_Shipping_Method\' ) ) {\n class WC_Your_Shipping_Method extends WC_Shipping_Method {\n /**\n …
Run Code Online (Sandbox Code Playgroud) 我正在努力更改默认选择的运输选项。仅当客户购物车中的金额超过 70 美元以上时,才会显示“免费送货”送货选项。如果购物车中的金额低于 70 美元,运输选项将不会显示在运输选项中。
如果客户的金额超过 70 美元或以上,则会显示“免费送货”选项,并且它应该是默认选择的送货选项。
我尝试添加以下代码片段,但它似乎对我不起作用,或者修改 ID 时可能出现错误(不确定)。
add_action( 'woocommerce_before_cart', 'set_default_chosen_shipping_method', 5 );
function set_default_chosen_shipping_method(){
//
if( count( WC()->session->get('shipping_method_0')['rates'] ) > 0 ){
foreach( WC()->session->get('shipping_method_0')['rates'] as $rate_id =>$rate)
if($rate->method_id == 'free_shipping30'){
$default_rate_id = array( $rate_id );
break;
}
WC()->session->set('chosen_shipping_methods', $default_rate_id );
}
}
Run Code Online (Sandbox Code Playgroud)
我在这里得到了这个片段的想法
先感谢您!!
我一直在尝试多种解决方案,以编程方式通过Woocommerce设置运输价格(每订单)。我没有运气
我尝试覆盖该项目的元值:
update_post_meta( $woo_order_id, '_order_shipping', $new_ship_price );
Run Code Online (Sandbox Code Playgroud)
还尝试了一些与此[问题/答案] [1]相似的方法
$item_ship = new WC_Order_Item_Shipping();
$item_ship->set_name( "flat_rate" );
$item_ship->set_amount( $new_ship_price );
$item_ship->set_tax_class( '' );
$item_ship->set_tax_status( 'none' );
// Add Shipping item to the order
$order->add_item( $item_ship );
Run Code Online (Sandbox Code Playgroud)
但是似乎都不起作用。任何指针最欢迎。
我正在尝试在 WooCommerce 单一产品页面上显示产品的运输类别名称和运输统一费率。我使用了下面的代码:
$shipping_class_id = $product->get_shipping_class_id();
$shipping_class= $product->get_shipping_class();
$fee = 0;
if ($shipping_class_id) {
$flat_rates = get_option("woocommerce_flat_rates");
$fee = $flat_rates[$shipping_class]['cost'];
}
$flat_rate_settings = get_option("woocommerce_flat_rate_settings");
echo 'Shipping cost: ' . ($flat_rate_settings['cost_per_order'] + $fee);
Run Code Online (Sandbox Code Playgroud)
我可以使用此代码获取运输类别 ID 以及运输类别 slug,但不能获取标签。我也无法获得该特定运输等级的费用,该费用是运输区域部分中定义的 5 欧元的统一费率。
期待您的回复。
有人问了下面的问题,我已经回答了。然后他就把它删除了。因此,我发布了问题和我的答案,因为这对社区有用:
在 WooCommerce 中,我尝试动态更新复选框表单而不重新加载结账页面。我有 2 种运输方式:“送货”和“自提”。我试图仅禁用送货地址部分(使用“如果选择的方法是收集,则运送到另一个地址”复选框选项)和所有送货字段。
首先我尝试了这个:
add_action( 'woocommerce_after_shipping_rate', 'carrier_custom_fields', 30, 2 );
function carrier_custom_fields( $method, $index ) {
if( ! is_checkout()) return; // Only on checkout page
$customer_carrier_method = 'local_pickup:1';
if( $method->id != $customer_carrier_method ) return; // Only display for "local_pickup"
$chosen_method_id = WC()->session->chosen_shipping_methods[ $index ];
// echo $chosen_method_id;
// If the chosen shipping method is 'legacy_local_pickup' we display
if($chosen_method_id == $customer_carrier_method ):
add_filter( 'woocommerce_cart_needs_shipping_address', '__return_false');
else :
add_filter( 'woocommerce_cart_needs_shipping_address', '__return_true');
endif;
}
Run Code Online (Sandbox Code Playgroud)
然后我尝试了这个:
add_action( 'woocommerce_shipping_method_chosen', 'check_if_local_pickup', …
Run Code Online (Sandbox Code Playgroud) 我在运输区域内设置了两种统一费率运输方式。在结账时,这两种运输方式都可用。
我想在每个统一运费选项下显示文字说明。在 WooCommerce 中似乎没有任何选项可以做到这一点。
我已经尝试了以下代码,但不用说它不起作用:
add_filter( 'woocommerce_page_title', 'woo_shop_page_title');
function wc_get_shipping_zone( $package ) {
if( $package == 'flat_rate:1') {
return "<p>Arriving on your chosen date between 9am - 1pm Perfect for business addresses & special occasions</p>";
}
if( $package == 'flat_rate:2') {
return "<p>Arriving on your chosen date between 9am - 7pm Perfect for residential addresses</p>";
}
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮助完成这项工作吗?
这就是我希望结帐时的描述:
我正在尝试获取所有运输方式及其费率和名称。但是当我使用它时,WC()->shipping->get_shipping_methods()
它只会返回空的费率数组和空的标题字符串。这是一个转储:
array (size=3)
'flat_rate' =>
object(WC_Shipping_Flat_Rate)[1861]
protected 'fee_cost' => string '' (length=0)
public 'supports' =>
array (size=3)
0 => string 'shipping-zones' (length=14)
1 => string 'instance-settings' (length=17)
2 => string 'instance-settings-modal' (length=23)
public 'id' => string 'flat_rate' (length=9)
public 'method_title' => string 'Flat rate' (length=9)
public 'method_description' => string 'Lets you charge a fixed rate for shipping.' (length=42)
public 'enabled' => string 'yes' (length=3)
public 'title' => string '' (length=0)
public 'rates' =>
array (size=0)
empty
public 'tax_status' …
Run Code Online (Sandbox Code Playgroud) 我通过更改模板在运输方式部分添加了两个自定义输入字段,/genesis-sample/woocommerce/checkout/review-order.php
我还设法使它们有条件地需要。只有当特定的单选按钮被选中时,输入字段才会出现并成为必需的。我正在使用 jQuery 代码使字段出现和消失。所有这些都运行良好。代码在这里:
if ( isset($_POST['shipping_method_0_legacy_local_pickup']) && $_POST['shipping_method_0_legacy_local_pickup'] == 1 ) {
$cheq = 'true';
}
else {
$cheq = 'false';
}
woocommerce_form_field( 'fieldtester1' , array(
'type' => 'text',
'class' => array('wccs-field-class wccs-form-row-wide blahblah1'),
'label' => 'Enter Your Carrier Name',
'required' => $cheq,
'placeholder' => 'Carrier Name',
), $checkout->get_value( 'fieldtester1' ));
woocommerce_form_field( 'fieldtester2' , array(
'type' => 'text',
'class' => array('wccs-field-class wccs-form-row-wide blahblah2'),
'label' => 'Enter Your Carrier Account #',
'required' => $cheq,
'placeholder' => 'Carrier Number',
), …
Run Code Online (Sandbox Code Playgroud) 我有两种运输方式。第一个是免费送货,第二个是我收取额外费用的快递运费统一运费。默认情况下,在购物车中选择快递运输,这会导致一些买家感到困惑,因为我不提供免费送货服务。
是否可以将默认选择的方法更改为免费送货?