在我的自定义插件中,我需要捕获每次订单状态从 变为 的情况,wc_on_hold
因此wc_completed
我尝试写下:
function so_status_completed( $order_id, $old_status, $new_status ) {
// if user is active , then get order amount and do all other personal calculations
global $wpdb;
$order = wc_get_order( $order_id );
//$payment_method = $order->get_payment_method(); //returns payment method bacs,cheque,cod etc
$user_id = $order->get_user_id();
$total = $order->get_total();
$order_data = $order->get_data();
//$order_total = $order->get_formatted_order_total();
$order_total = $order->get_total();
echo '<script>console.log("Debug Objects: Check order_total ' . $order_total. '");</script>';
}
add_action('woocommerce_order_payment_status_changed','so_status_completed',10,1);
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试将订单测试从暂停更改为完成时,我无法在 Chrome 控制台上回显给我订单价格......也许使用 add_action 不是将侦听器置于该事件的正确方法?
另外,由于我就在这里,我正在使用 $order-get_total() ,我在网上搜索了它的功能,但没有找到深入的文档,所以我想问你该方法是否是免费检索订单金额的正确方法应用?
谢谢!干杯!!!
wordpress orders woocommerce hook-woocommerce woocommerce-theming
如何更改循环中的 WooCommerce 产品标题,例如更改shop, category
页面中的产品图块等?
我正在寻找可以帮助解决这个问题的钩子。去的时候woocommerce/content-product.php
显示
do_action('woocommerce_before_shop_loop_item_title');
echo '<div class="title-wrapper">';
do_action('woocommerce_shop_loop_item_title');
echo '</div>';
Run Code Online (Sandbox Code Playgroud)
请帮忙
我想更改产品图块shop page, category page
等。但在single product page, or cart, checkout
页面中我不想更改标题。还有简码呢[products ids="12,34,56,"];
?
我怎样才能更改标题?
wordpress woocommerce woothemes hook-woocommerce woocommerce-theming
我的博客侧边栏search form
上有一个简单的搜索方式.blogs
<form action="<?php echo get_site_url() ?>" method="GET">
<input type="search" name="s" placeholder="Click to Search" class="fld-search" required/>
<input type="hidden" name="post_type" value="post">
<button class="btn-search"><i class="fa fa-search" aria-hidden="true"></i></button>
</form>
Run Code Online (Sandbox Code Playgroud)
这是网址网址:http://dev.wonder.lk/blog/
以下是我应用的搜索类型,
hello
(但您可以Hello World
在存档上看到博客)post_type
值 - 结果是一个空白页面,即使我看不到页眉或页脚.例如:搜索ninja
它是一种产品类型这些是代码,
search.php中
<?php
while ( have_posts() ) : the_post();
if(isset($_GET['post_type'])) {
$type = $_GET['post_type'];
if($type == 'product') {
get_template_part( 'woocommerce/archive', 'product' ); //working fine
} …
Run Code Online (Sandbox Code Playgroud) php wordpress wordpress-theming woocommerce woocommerce-theming
我正在尝试将这个难题的所有部分拼凑在一起。在过去的三天里,我一直在阅读有关此主题的所有问题和答案。所以我遵循的总体蓝图如下:
woocommerce_variable_add_to_cart();
函数来输出正确的 html。这是我每个部分的代码:
global $post;
$product = wc_get_product($post->ID);
$product_type = $product->get_type();
Run Code Online (Sandbox Code Playgroud)
if($product_type == 'variable'):
woocommerce_variable_add_to_cart();
endif;
Run Code Online (Sandbox Code Playgroud)
add_filter('woocommerce_dropdown_variation_attribute_options_html', 'my_theme_variation_radio_buttons', 20, 2);
function my_theme_variation_radio_buttons($html, $args)
{
$args = wp_parse_args(apply_filters('woocommerce_dropdown_variation_attribute_options_args', $args), array(
'options' => false,
'attribute' => false,
'product' => false,
'selected' => false,
'name' => '',
'id' => '', …
Run Code Online (Sandbox Code Playgroud) ajax woocommerce woocommerce-theming product-variations variable-product
我想获取我在我的中使用以下代码的购物车总数functions.php
:
function display_total(){
global $woocommerce;
$newTotal = $woocommerce->cart->get_total();
echo $newTotal;
};
add_action( 'woocommerce_review_order_before_order_total', 'display_total');
Run Code Online (Sandbox Code Playgroud)
它不是显示一次金额,而是像 那样显示两次$18.00$18.00
。
执行 a 操作var_dump
也会生成 2 行 HTML:
D:\Wordpress\wp-content\themes\new_theme\functions.php:161:string '<span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">$</span>18.00</bdi></span>' (length=128)
D:\Wordpress\wp-content\themes\new_theme\functions.php:161:string '<span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">$</span>18.00</bdi></span>' (length=128)
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
php wordpress woocommerce hook-woocommerce woocommerce-theming
我在 WooCommerce 产品上为帖子类型设置了高级自定义字段。因此每个产品都有 1 个独特的自定义字段。
我试图在购物车上的产品名称以及结账页面和订单表信息之后显示自定义字段。
但是,由于我的代码不显示任何输出,因此遇到了问题。
任何有关如何实现这一目标的建议将不胜感激。谢谢
// Display the ACF custom field 'location' after the product title on cart / checkout page.
function cart_item_custom_feild( $cart_item ) {
$address = get_field( 'location', $cart_item['product_id'] );
echo "<div>Address: $address.</div>";
}
add_action( 'woocommerce_after_cart_item_name', 'cart_item_custom_feild', 10, 1 );
Run Code Online (Sandbox Code Playgroud)
我也尝试过the_field
而不是get_field
php wordpress woocommerce advanced-custom-fields woocommerce-theming
我发现可以添加自定义字段以在 WooCommerce 中对产品进行排序(例如这个问题)从示例中复制:
add_filter( 'woocommerce_get_catalog_ordering_args', 'enable_catalog_ordering_by_modified_date' );
function enable_catalog_ordering_by_modified_date( $args ) {
if ( isset( $_GET['orderby'] ) ) {
if ( 'modified_date' == $_GET['orderby'] ) {
return array(
'orderby' => 'modified', //This is the custom field to be sorted by, and what I am asking for
'order' => 'DESC',
);
}
}
return $args;
}
Run Code Online (Sandbox Code Playgroud)
是否有可用于排序的所有字段的列表?
PS:感谢您的评论,但我需要的不是对 WordPress 中的普通帖子进行排序,而是对 WooCommerce 中的产品进行排序。
我已经更新了模板,但状态报告仍然显示版本已过时,即使它们不是......
...如何刷新状态报告以便为版本开绿灯?
谢谢!
我已经在本地更新了文件并也上传到实时服务器,但是两个版本都在状态报告中显示警告,它们似乎是间歇性更新的,但我想触发刷新。
我想使用 woocommerce 挂钩woocommerce_order_status_changed。当新的订单状态为垃圾时,我想解雇一些东西。
我使用了这个函数,它对于剩余订单状态(垃圾除外)非常有效。
这是我的代码:
function custom_order_actions ( $order_id, $old_status, $new_status ){
$order = new WC_Order($order_id);
if ($new_status == 'trash') {
// Do something
}
}
add_action( 'woocommerce_order_status_changed', 'custom_order_actions', 99, 3 );
Run Code Online (Sandbox Code Playgroud) php wordpress woocommerce hook-woocommerce woocommerce-theming
我想在变体名称后添加内容。
我找到这个钩子并看到它之前可以工作,但在我的测试中它不是:(
我想问,是否有另一种钩子/工作方法可以用来添加内容?
add_filter('woocommerce_attribute_label', 'custom_attribute_label', 10, 3);
function custom_attribute_label($label, $name, $product){
$taxonomy = 'pa_' . $name;
if ($taxonomy == 'pa_size')
$label .= '<div class="custom-label">' . __('MY TEXT', 'woocommerce') . '</div>';
return $label;
}
Run Code Online (Sandbox Code Playgroud)
php wordpress woocommerce hook-woocommerce woocommerce-theming