我想在 WooCommerce 结账时获取购物车中商品的类别。我想提取它,然后将其放置在我的自定义结帐中的字段中。
我正在使用WooCommerce MultiStep Checkout Wizard高级插件和特定的挂钩:
add_action('woocommerce_multistep_checkout_before_order_info', 'destinationStep');
Run Code Online (Sandbox Code Playgroud)
我有点迷失了,找不到太多我需要用来获取它的 文档。
我试图让项目出现,但我只得到一个空数组。
$order = new WC_Order( $order_id );
$items = $order->get_items();
var_dump($items);
Run Code Online (Sandbox Code Playgroud) 互联网上的大多数文章都是关于如何删除/替换“查看产品”或“了解更多”按钮。
我找不到与允许两个按钮一起工作相关的内容。
我感兴趣的是让两个按钮并行工作(同时)。要显示的第一个按钮应该是“查看产品”(在同一页面上打开),然后在“添加到购物车”下方
目前,我的商店仅显示“添加到购物车”按钮。我正在使用店面主题(+自定义子主题)。
有人会这么好心告诉我该怎么做吗?
我正在尝试按元值和元键显示产品。我使用下面的代码来验证元键和元值。现在,如果没有值为“yes_feat”的meta_keys,则不会打印产品。这太棒了!
问题是,如果只有 1 个产品的 meta_keys 值为“yes_feat”,则所有其他产品也会打印。如何使其仅显示具有元值“yes_feat”的产品
$params = array(
'post_type' => 'product',
'meta_key' => '_featured',
'meta_value' => 'yes_feat',
'posts_per_page' => 5
);
$wc_query = new WP_Query($params);
global $post, $product;
if ($wc_query->have_posts()) {
// i am only trying to print products with meta_value = yes_feat
// but if the statement above is true it prints all products
echo "print products that have meta_value = yes_feat";
}
else
{
echo "nothing found";
}
Run Code Online (Sandbox Code Playgroud)
多谢
php wordpress wordpress-theming woocommerce hook-woocommerce
您好,我使用的是 Woocommerce 版本 3.2.6。我们有一些订单。
我想在 wordpress 后端的订单编辑页面中product id为订单添加一项额外的详细信息。123
我想添加这个:
<a href="http://example.com/new-view/?id=<?php echo $order_id?;>">Click here to view this</a>
Run Code Online (Sandbox Code Playgroud)
即:我们有order[order id =3723],订购的商品 id 是123。
然后在 中http://example.com/wp-admin/post.php?post=3723&action=edit,我想在相应的项目详细信息下方添加以下链接:
"<a href="http://example.com/new-view/?id=<?php echo $order_id?;>">Click here to view this</a>"
Run Code Online (Sandbox Code Playgroud)
我们怎样才能做到这一点?
哪个钩子适合这个。实际上我正在搜索https://docs.woocommerce.com/wc-apidocs/hook-docs.html。
我找到了 Class WC_Meta_Box_Order_Items。但我不知道如何使用这个。
我们需要传递以下 WooCommerce 参数,但我们不能并且出现错误。
主要问题是获取所有产品数量、购买的每种产品的数量、产品 SKU
这是我们的代码:
add_action( 'woocommerce_thankyou', 'the_tracking' );
function the_tracking( $order_id ) {
global $woocommerce;
$order = wc_get_order( $order_id );
$total = $order->get_total();
$currency = get_woocommerce_currency();
$subtotal = $woocommerce->cart->subtotal;
$coupons = $order->get_used_coupons();
$coupon_code = '';
$discount = $order->get_total_discount();
foreach ($coupons as $coupon){
$coupon_code = $coupon;
}
$tracking = 'OrderID='.$order.'&ITEMx=[ItemSku]&AMTx=[AmountofItem]&QTYx=[Quantity]&CID=1529328&OID=[OID]&TYPE=385769&AMOUNT='. $total .'&DISCOUNT='. $discount .'&CURRENCY='. $currency .'&COUPON='. $coupon_code .'';
echo $tracking;
}
Run Code Online (Sandbox Code Playgroud)
但它并没有给我们带来我们应该需要的预期结果。
任何帮助表示赞赏。
当我为客户创建自定义订单时,他们必须在自己的帐户中付款。但当他们访问订单支付页面时,没有显示运输和账单字段。怎么做 ?
我知道模板是form-pay.php
谢谢
我想在 woocommerce 结帐页面上添加 300 到订单总数,但 woocommerce_calculate_totals 钩子没有完成这项工作......
如果我使用 var_dump($total),我会看到正确的结果 - int(number),但订单表中的总金额没有改变。
add_action( 'woocommerce_calculate_totals', 'action_cart_calculate_totals', 10, 1 );
function action_cart_calculate_totals( $cart_object) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
if ( !WC()->cart->is_empty() ):
$total = $cart_object->cart_contents_total += 300;
var_dump($total);
endif;
}
Run Code Online (Sandbox Code Playgroud) 我想更改 WooCommerce 我的帐户部分中每个页面的页面标题(条目标题),以便它们与您所在的实际页面相关,而不是在每个页面上输出通用的“我的帐户”。
我环顾四周,在几个地方看到了这个解决方案:
function wpb_woo_endpoint_title( $title, $id ) {
if ( is_wc_endpoint_url( 'downloads' ) && in_the_loop() ) { // add your endpoint urls
$title = "Download MP3s"; // change your entry-title
}
elseif ( is_wc_endpoint_url( 'orders' ) && in_the_loop() ) {
$title = "My Orders";
}
elseif ( is_wc_endpoint_url( 'edit-account' ) && in_the_loop() ) {
$title = "Change My Details";
}
return $title;
}
add_filter( 'the_title', 'wpb_woo_endpoint_title', 10, 2 );
Run Code Online (Sandbox Code Playgroud)
这并不会,除非你删除的工作in_the_loop检查,这显然不是理想的,因为那么它最终在页面上改变其他的一些东西。
然后我找到了这个答案,例如如何更改“帐户详细信息”页面的标题:
add_filter( …Run Code Online (Sandbox Code Playgroud) 我有一些基本的 Woocommerce 问题,在网上找不到任何地方。
谢谢!
global $product;
echo apply_filters( 'woocommerce_loop_add_to_cart_link', // WPCS: XSS ok.
sprintf( '<a href="%s" data-quantity="%s" class="%s" %s>%s</a>',
esc_url( $product->add_to_cart_url() ),
esc_attr( isset( $args['quantity'] ) ? $args['quantity'] : 1 ),
esc_attr( isset( $args['class'] ) ? $args['class'] : 'button' ),
isset( $args['attributes'] ) ? wc_implode_html_attributes( $args['attributes'] ) : '',
esc_html( $product->add_to_cart_text() )
),
$product, $args );
Run Code Online (Sandbox Code Playgroud) 我创建了自定义分类法“品牌”并附加到 woocommerce 产品。不幸的是,它在 woocommerce REST API 响应中不可用。如何将自定义分类术语附加到 woocommerce rest API。目前没有关于自定义分类法附件的文档。有没有钩子或过滤器?
hook-woocommerce ×10
woocommerce ×10
wordpress ×10
php ×9
checkout ×2
orders ×2
account ×1
cart ×1
product ×1
storefront ×1