好吧,我正在尝试为Woocommerce产品创建一些自定义循环页面,我发现该过程从archive-product.php文件开始,然后包括用于绘制页面的模板片段。
但是我想更改要查询的参数,因此它将加入某些产品类别,或从循环中排除某些产品或某些类别(就像我们在Wordpress项目中的category.php中所做的那样)。
我该怎么做?!在哪里可以找到脚本的这一部分?
谢谢!
我有这种情况 - 我对其中一个woocommerce电子邮件模板进行了更改,但我确定 - 这些更改将在下一次woocommerce更新后丢失.
据我所知,我应该使用主题函数来绕过这个问题.
这是更改前的代码:
echo '<ul class="wc-bacs-bank-details order_details bacs_details">' . PHP_EOL;
// BACS account fields shown on the thanks page and in emails
$account_fields = apply_filters( 'woocommerce_bacs_account_fields', array(
'account_number'=> array(
'label' => __( 'Account Number', 'woocommerce' ),
'value' => $bacs_account->account_number
),
'sort_code' => array(
'label' => $sortcode,
'value' => $bacs_account->sort_code
),
'iban' => array(
'label' => __( 'IBAN', 'woocommerce' ),
'value' => $bacs_account->iban
),
'bic' => array(
'label' => __( 'BIC', 'woocommerce' ),
'value' => $bacs_account->bic
) …Run Code Online (Sandbox Code Playgroud) 我需要在插件付款之前显示购物车中的订单详情.
我在一个插件上工作,连接woocommerce和支付API,我需要发送产品ID,名称,描述,数量和个人数量等产品详细信息.
我的问题是我找不到正确的钩子来正确获取所有数据.
我怎样才能获得这些数据?
谢谢
这里是基于anwers的更新,为每个需要它的人提供:
add_action('woocommerce_checkout_process', 'woocommerce_get_data', 10);
function woocommerce_get_data(){
$cart = array();
$items = WC()->cart->get_cart();
foreach($items as $i=>$fetch){
$item = $fetch['data']->post;
$cart[]=array(
'code' => $fetch['product_id'],
'name' => $item->post_title,
'description' => $item->post_content,
'quantity' => $fetch['quantity'],
'amount' => get_post_meta($fetch['product_id'], '_price', true)
);
}
$user = wp_get_current_user();
$data = array(
'total' => WC()->cart->total,
'cart' => $cart,
'user' => array(
'id' => $user->ID,
'name' => join(' ',array_filter(array($user->user_firstname, $user->user_lastname))),
'mail' => $user->user_email,
)
);
$_SESSION['woo_data']=json_encode($data);
}
Run Code Online (Sandbox Code Playgroud)
感谢@loictheaztec和@ raunak-gupta
我遇到的问题是购物车总数只显示0
基本上我想要做的只是在将所有购物车商品添加到购物车小计后才接受一定金额的存款.
因此,例如,如果客户增加价值100美元的物品,他们最初只需支付10美元或小计的(10%)作为总价值.
我从这里获取代码:更改total和tax_total Woocommerce并以这种方式自定义:
add_action('woocommerce_cart_total', 'calculate_totals', 10, 1);
function calculate_totals($wc_price){
$new_total = ($wc_price*0.10);
return wc_price($new_total);
}
Run Code Online (Sandbox Code Playgroud)
但是当启用该代码时,总金额显示为0.00.如果删除了代码,我会得到标准总数.
我也找不到列出完整api的woocommerce网站,只有与如何创建插件有关的通用文章.
任何帮助或正确方向上的一点都会很棒.
我在WordPress主题中添加了两个插件:
Lead Capture Pro是一个潜在客户生成插件。公司获得注册,可以查看可用的线索并购买。公司的登录屏幕通过WP-Admin login。在主题中激活WooCommerce后,我将重定向到"My Account Page"WooCommerce。我使用中的以下代码停止了此重定向functions.php。
function admin_bar(){
if(is_user_logged_in()){
add_filter( 'show_admin_bar', '__return_true' , 1000 );
}
}
add_action('init', 'admin_bar' );
add_filter( 'woocommerce_prevent_admin_access', '__return_false' );
add_filter( 'woocommerce_disable_admin_bar', '__return_false' );
Run Code Online (Sandbox Code Playgroud)
这会将我重定向到公司资料页面,他/她可以在其中查看销售线索和购买历史记录。
现在,我需要做的是只有一个页面,其中包含WooCommerce和Lead Capture Pro插件的两个菜单都具有相同的布局。我无法在自定义页面上调用Lead Capture Pro视图。需要一些指针。
以下代码对于单个产品正确运行,但是我想将此代码用于几种产品的多种变体。
实际上,此代码将销售价格与销售价格开始之前的原始价格相加。
我正在计划销售,我想同时显示销售价格和原始的预售价格,以便客户看到折扣可以节省多少。
function cw_change_product_price_display( $price_html ) {
global $product;
global $woocommerce;
if ( $product->is_on_sale() ) {
return $price_html;
} elseif($product->get_sale_price()){
$price =wc_price($product->get_sale_price());
return $price_html . $price;
} else {
return $price_html;
}
}
add_filter( 'woocommerce_get_price_html', 'cw_change_product_price_display' );
Run Code Online (Sandbox Code Playgroud) 我正在使用带有Storefront主题的WooCommerce来构建一个主要用于智能手机的电子商务网站.所以我试图减少点击次数和按钮数量,使其尽可能简单.
我想用数量选择器替换"添加到购物车"按钮:

我找到了一种在"添加到购物车"按钮旁边添加数量选择器的方法(例如,使用插件WooCommerce高级产品数量),但我想摆脱"添加到购物车"按钮.因此,当客户点击"+"时,它应该向购物车添加1个元素,并且数字应该显示购物车中的数量.
另外(不知道这是否可能......),我想要一个动画通知客户产品已经很好地添加到购物车中.例如,在购物车图标附近显示"+1"几秒钟,

每当cron运行自动续订我的客户端订阅时,我都会在错误日志中收到此信息.
[Wed Nov 22 06:45:01 2017] [error] [client 204.187.12.186] FastCGI: server "/php-completehumanperformancecom.fpm" stderr: Stack trace:, referer: http://completehumanperformance.com/wp-cron.php?doing_wp_cron=1511361900.1951580047607421875000
[Wed Nov 22 06:45:01 2017] [error] [client 204.187.12.186] FastCGI: server "/php-completehumanperformancecom.fpm" stderr: #0 [internal function]: WC_Subscriptions_Payment_Gateways::gateway_scheduled_subscription_payment(), referer: http://completehumanperformance.com/wp-cron.php?doing_wp_cron=1511361900.1951580047607421875000
[Wed Nov 22 06:45:01 2017] [error] [client 204.187.12.186] FastCGI: server "/php-completehumanperformancecom.fpm" stderr: #1 /var/home/hybrid/completehumanperformance.com/www/wp-includes/class-wp-hook.php(298): call_user_func_array('WC_Subscription...', Array), referer: http://completehumanperformance.com/wp-cron.php?doing_wp_cron=1511361900.1951580047607421875000
[Wed Nov 22 06:45:01 2017] [error] [client 204.187.12.186] FastCGI: server "/php-completehumanperformancecom.fpm" stderr: #2 /var/home/hybrid/completehumanperformance.com/www/wp-includes/class-wp-hook.php(323): WP_Hook->apply_filters('', Array), referer: http://completehumanperformance.com/wp-cron.php?doing_wp_cron=1511361900.1951580047607421875000
[Wed Nov 22 06:45:01 2017] [error] [client 204.187.12.186] FastCGI: …Run Code Online (Sandbox Code Playgroud) 目标:过滤或修改通过woocommerce_json_search_products_and_variations获取的结果
我正在尝试过滤通过ajax调用获取的产品site-url-/wp-admin/post-new.php?post_type=shop_order(woocommerce中的手动添加订单)
命中网址 site-url/wp-admin/admin-ajax.php?term=test&action=woocommerce_json_search_products_and_variations&security=xxxxx
我找不到合适的woocommmerce hook/filter来对此进行修改。
请提出建议。我可以从那里编码。 进行产品ajax调用的屏幕。
我正在尝试在创建新的运输区域时向“ Woocommerce 运输”选项卡及其“ 运输区域”部分添加一个选择字段。我在寻找解决方案时在Woocommerce的官方文档中找到了这一点。
到目前为止,我尝试过的是:
// Fires on 'plugins_loaded' action of WordPress
public function plugins_loaded_action() {
add_filter( 'woocommerce_get_settings_shipping', array( $this, 'shipping_zone_settings_add_city_field' ), 10, 2 );
}
public function shipping_zone_settings_add_city_field( $settings, $current_section ) {
echo 'this runs only for shipping_options section';
/**
* Check the current section for shipping zone
*/
if( $current_section === 'shipping_zones' ) {
// Add city field to settings
$settings[] = array(
array(
'name' => __( 'Zone City', 'woocommerce' ),
'type' => 'title', …Run Code Online (Sandbox Code Playgroud)