为什么在主题的'function.php'文件中放置WooCommerce功能修改是首选?加班,这会使文件相当大.我的理解是,通常更好的做法是拥有大量组织良好的小文件,而不是更少的大文件.
考虑到这一点,将'wc-template-functions.php'和'wc-templates-hooks.php'文件复制到主题中(同时保持其文件层次结构)并相应地修改这些文件有什么问题?
作为一个侧面请求,从一个相对新手到WooCommerce平台,我会很感激,如果我能得到一个'是的,那个有效'或'不,我已经错过了一些东西'回应我对WooCommerce的理解; 文件,钩子,动作和模板都可以与其中一个一起使用
我的理解:
woocommerce_breadcrumb条目.add_action('woocommerce_before_main_content','woocommerce_breadcrumb', 20, 0 ); 这只是指向woocommerce_breadcrumb在woocommerce_before_main_content钩子内调用.do_action( 'woocommerce_before_main_content' );在必要的位置来输出上述内容.在这种情况下,在所有模板文件中.jQuery函数需要在发布选项更新后,在结帐页面上,通过ajax调用初始化,并且updated_shipping_method已触发Woocommerce自定义事件.
我的jQuery代码片段设置为侦听此事件 - 但这不符合预期.
jQuery( document.body ).on( 'updated_shipping_method', function(){
// Code stuffs
// has the function initialized after the event trigger?
console.log('on updated_shipping_method: function fired');
});
Run Code Online (Sandbox Code Playgroud)
我也尝试过updated_wc_div自定义事件但无济于事.
我在购物车页面上使用类似的方法,几乎逐字逐句地听取自定义事件触发器updated_cart_totals并且它完美地工作.不确定为什么结帐页面不是这种情况.
由于有一个命令:
wp_insert_post()
Run Code Online (Sandbox Code Playgroud)
应该没有命令:
wp_delete_post()
Run Code Online (Sandbox Code Playgroud)
似乎它不存在,当您在数据库中拥有产品ID并想要删除它时,可以使用什么替代方法?
单击购物车页面中的更新购物车按钮后,我需要知道哪个挂钩正在运行。
也就是说,在购物车页面中,我们有 4 个按钮 , update cart, continue shopping, proceed to checkout, apply coupon。
所以我想知道点击更新购物车按钮后运行哪个钩子。当客户在更改数量后单击更新购物车按钮时,我必须运行一个可以更改购物车中总价的特殊功能,如果满足某些条件,我将更改购物车中的总价,并且该总价需要传递。也到结帐页面 /
请帮忙 。
例如
add_filter('after_update_cart_function_finished', 'special_function');
function special_function(){
$applied_coupons= WC()->cart->get_applied_coupons();
if(!empty($applied_coupons)){
$new_value=WC()->cart->get_cart_subtotal();
$discounted=WC()->cart->coupon_discount_totals;
$discounted_value=array_values($discounted)[0];
$new_value=$new_value-$discounted_value+100;
WC()->cart->set_total_price($new_value);
After this update all post_meta value that regarding to order total
}
}
Run Code Online (Sandbox Code Playgroud)
请参阅我编写的以下自定义函数以更改购物车中的值
function action_woocommerce_cart_totals_after_order_total( ) {
$applied_coupons= WC()->cart->get_applied_coupons();
if(!empty($applied_coupons)){
$new_value=WC()->cart->get_cart_subtotal();
$discounted=WC()->cart->coupon_discount_totals;
$discounted_value=array_values($discounted)[0];
$new_value=$new_value-$discounted_value;
if($new_value<100){
$new_value=$new_value+5;
}
?>
<style>
.new-price-new{
color:black;
font-size: 17px;
}
</style>
<script>
jQuery(function($){
$(".order-total .woocommerce-Price-amount.amount").text("£<?php echo $new_value;?>");
$(".order-total .woocommerce-Price-amount.amount").hide();
$(".new-price").remove(); …Run Code Online (Sandbox Code Playgroud) 我想将WooCommerce订单状态从"已完成"重命名为"已收到订单".我可以编辑下面wc-order-functions.php中的脚本,但我不想修改任何核心文件或使用插件.
是否可以使用子主题functions.php文件中的脚本覆盖woocoomerce函数?
function wc_get_order_statuses() {
$order_statuses = array(
'wc-pending' => _x( 'Pending Payment', 'Order status', 'woocommerce' ),
'wc-processing' => _x( 'Processing', 'Order status', 'woocommerce' ),
'wc-on-hold' => _x( 'On Hold', 'Order status', 'woocommerce' ),
'wc-completed' => _x( 'Completed', 'Order status', 'woocommerce' ),
'wc-cancelled' => _x( 'Cancelled', 'Order status', 'woocommerce' ),
'wc-refunded' => _x( 'Refunded', 'Order status', 'woocommerce' ),
'wc-failed' => _x( 'Failed', 'Order status', 'woocommerce' ),
);
return apply_filters( 'wc_order_statuses', $order_statuses );
}
Run Code Online (Sandbox Code Playgroud) 这是问题所在.我的woocommerce网站有3种不同的付款方式 -
如果我的买家以"支票付款"结帐,我想向他发送一封自动发送的电子邮件,其中概述了支票付款的步骤.如果他与"西联汇款"签出,我想通过电子邮件将他的西联汇款信息发送给他.应发送另一封自动电子邮件以进行货到付款.
通常在Woocommerce中,您有一封电子邮件发送给客户完成所有已完成的订单,在我的情况下,根据付款选项,我需要3封不同的电子邮件.
所以我开始使用本教程制作自定义电子邮件 - https://www.skyverge.com/blog/how-to-add-a-custom-woocommerce-email/
上面的教程用于制作自定义电子邮件以加快运输.这是教程中使用的代码行 -
// bail if shipping method is not expedited
if ( ! in_array( $this->object->get_shipping_method(), array( 'Three Day Shipping', 'Next Day Shipping' ) ) )
return;
Run Code Online (Sandbox Code Playgroud)
如果我想检查付款方式是什么,那么代码行是什么?我想检查付款方式是否为"支票付款",以便我可以向他发送自定义电子邮件.
如果您有任何想法,请告诉我.
我想在WooCommerce中创建具有相同SKU的多个简单产品.我在管理员设置中搜索,但在那里我找不到任何设置来启用此功能.有没有钩子所以我可以禁用此功能.
我正在尝试申请autocomplete="off"我的WooCommerce结帐字段,但它不起作用.
结账表格有没有办法做到这一点?
我检查了文档,那里没有任何可用的东西.我也尝试将默认值设置为空,但它也不起作用.这是用户当然没有登录的时间.
更新:
我unset按照@smvax的建议尝试过,但它没有用.
add_filter('woocommerce_checkout_fields', 'default_values_checkout_fields');
function default_values_checkout_fields($fields) {
if (!is_user_logged_in()) {
unset($fields['billing_city']);
unset($fields['billing_first_name']);
unset($fields['billing_last_name']);
unset($fields['billing_company']);
unset($fields['billing_address_1']);
unset($fields['billing_address_2']);
unset($fields['billing_city']);
unset($fields['billing_postcode']);
unset($fields['billing_country']);
unset($fields['billing_state']);
unset($fields['billing_email']);
unset($fields['billing_phone']);
unset($fields['shipping_city']);
unset($fields['shipping_first_name']);
unset($fields['shipping_last_name']);
unset($fields['shipping_company']);
unset($fields['shipping_address_1']);
unset($fields['shipping_address_2']);
unset($fields['shipping_postcode']);
unset($fields['shipping_country']);
unset($fields['shipping_state']);
return $fields;
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢
我正在尝试更改WooCommerce Registration表单的最小密码强度,我无法做多少.
任何人都可以分享一个解决方案,通过该解决方案,我可以修改最小密码强度,并允许用户使用长度为7个字符且内部不需要任何符号或大写字母的密码?
谢谢.