GVKun编程网logo

php – Woocommerce | WordPress – WC_Cart :: set_quantity –(wordpress chatbot)

3

以上就是给各位分享php–Woocommerce|WordPress–WC_Cart::set_quantity–,其中也会对wordpresschatbot进行解释,同时本文还将给你拓展php–Wo

以上就是给各位分享php – Woocommerce | WordPress – WC_Cart :: set_quantity –,其中也会对wordpress chatbot进行解释,同时本文还将给你拓展php – Woocommerce WC_Cart->费用和WC_Cart :: get_checkout_url已弃用、php – WordPress Woocommerce – 使用update_post_meta添加产品属性、php – 将自定义帖子类型与电子商务集成(Woocommerce o others) – WORDPRESS、WooCommerce php 8.1 + WordPress 5.7.2等相关知识,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

php – Woocommerce | WordPress – WC_Cart :: set_quantity –(wordpress chatbot)

php – Woocommerce | WordPress – WC_Cart :: set_quantity –(wordpress chatbot)

我正在开发一个电子商务网站.
我正在尝试使用ajax请求设置购物车项目数量.

我懂了

if (isset($_POST['product_id']) && isset($_POST['new_quantity'])) {
   global $woocommerce;
   $woocommerce->cart->set_quantity($_POST['product_id'], $_POST['new_quantity']);
}

我也尝试过

WC()->....

但它不起作用并抛出此错误

Call to a member function needs_shipping() on null in
C:\xampp\htdocs\findandcandy\wp-content\plugins\woocommerce\includes\class-wc-cart.PHP on line 1514

是什么导致这种情况发生?

如果您需要我显示更多代码,请告诉我.
谢谢

解决方法:

好的,您现在可以更新购物车商品的数量而无需通过AJAX刷新(:

我的functions.PHP看起来像这样

//Enqueue Ajax Scripts
function enqueue_cart_qty_ajax() {

    wp_register_script( 'cart-qty-ajax-js', get_template_directory_uri() . '/js/cart-qty-ajax.js', array( 'jquery' ), '', true );
    wp_localize_script( 'cart-qty-ajax-js', 'cart_qty_ajax', array( 'ajax_url' => admin_url( 'admin-ajax.PHP' ) ) );
    wp_enqueue_script( 'cart-qty-ajax-js' );

}
add_action('wp_enqueue_scripts', 'enqueue_cart_qty_ajax');

function ajax_qty_cart() {

    // Set item key as the hash found in input.qty's name
    $cart_item_key = $_POST['hash'];

    // Get the array of values owned by the product we're updating
    $threeball_product_values = WC()->cart->get_cart_item( $cart_item_key );

    // Get the quantity of the item in the cart
    $threeball_product_quantity = apply_filters( 'woocommerce_stock_amount_cart_item', apply_filters( 'woocommerce_stock_amount', preg_replace( "/[^0-9\.]/", '', filter_var($_POST['quantity'], FILTER_SANITIZE_NUMBER_INT)) ), $cart_item_key );

    // Update cart validation
    $passed_validation  = apply_filters( 'woocommerce_update_cart_validation', true, $cart_item_key, $threeball_product_values, $threeball_product_quantity );

    // Update the quantity of the item in the cart
    if ( $passed_validation ) {
        WC()->cart->set_quantity( $cart_item_key, $threeball_product_quantity, true );
    }

    // Refresh the page
    echo do_shortcode( '[woocommerce_cart]' );

    die();

}

add_action('wp_ajax_qty_cart', 'ajax_qty_cart');
add_action('wp_ajax_nopriv_qty_cart', 'ajax_qty_cart');

我的cart-qty-ajax.js看起来像这样.

jQuery( function( $) {

    $( document ).on( 'change', 'input.qty', function() {

        var item_hash = $( this ).attr( 'name' ).replace(/cart\[([\w]+)\]\[qty\]/g, "$1");
        var item_quantity = $( this ).val();
        var currentVal = parseFloat(item_quantity);

        function qty_cart() {

            $.ajax({
                type: 'POST',
                url: cart_qty_ajax.ajax_url,
                data: {
                    action: 'qty_cart',
                    hash: item_hash,
                    quantity: currentVal
                },
                success: function(data) {
                    $( '.view-cart-popup' ).html(data);
                }
            });  

        }

        qty_cart();

    });

});

php – Woocommerce WC_Cart->费用和WC_Cart :: get_checkout_url已弃用

php – Woocommerce WC_Cart->费用和WC_Cart :: get_checkout_url已弃用

在我更新插件后,我想知道我的Woocommerce发生了什么.发生了一些弃用错误.请参阅下面的附图.我怎么能解决这个问题?

enter image description here

解决方法:

1)你需要用wc_get_checkout_url()替换WC_Cart :: get_checkout_url,而不使用WC() – > cart(或WC_Cart::),因为它不再是WC_Cart方法.

2)对于WC_Cart->费用,您可以将其替换为WC_Cart->get_fees()或WC() – > cart-> get_fees();

php – WordPress Woocommerce – 使用update_post_meta添加产品属性

php – WordPress Woocommerce – 使用update_post_meta添加产品属性

我客户网站上的产品需要我通过产品添加的某些属性 – > wordpress管理中的属性.在这个导入脚本中我编码我需要使用函数update_post_Meta($post_id,$Meta_key,$Meta_value)来导入适当的属性和值.

目前我有这样的功能:

update_post_Meta( $post_id,'_product_attributes',array());

但是我不确定如何正确传递属性及其值?

是的,所以我花了一段时间来弄清楚自己,但我终于设法通过编写以下函数来做到这一点:
// @param int $post_id - The id of the post that you are setting the attributes for
// @param array[] $attributes - This needs to be an array containing ALL your attributes so it can insert them in one go
function wcproduct_set_attributes($post_id,$attributes) {
    $i = 0;
    // Loop through the attributes array
    foreach ($attributes as $name => $value) {
        $product_attributes[$i] = array (
            'name' => htmlspecialchars( stripslashes( $name ) ),// set attribute name
            'value' => $value,// set attribute value
            'position' => 1,'is_visible' => 1,'is_variation' => 1,'is_taxonomy' => 0
        );

        $i++;
    }

    // Now update the post with its new attributes
    update_post_Meta($post_id,$product_attributes);
}

// Example on using this function
// The attribute parameter that you pass along must contain all attributes for your product in one go
// so that the wcproduct_set_attributes function can insert them into the correct Meta field.
$my_product_attributes = array('hdd_size' => $product->hdd_size,'ram_size' => $product->ram_size);

// After inserting post
wcproduct_set_attributes($post_id,$my_product_attributes);

// Woohay done!

我希望这个功能可以帮助其他人,如果他们需要在WooCommerce中以编程方式导入多个属性!

php – 将自定义帖子类型与电子商务集成(Woocommerce o others) – WORDPRESS

php – 将自定义帖子类型与电子商务集成(Woocommerce o others) – WORDPRESS

如何在wordpress中将电子商务插件与现有的cystom post类型集成?
我创建了一个带有很多选项和分类的自定义帖子类型.现在我(非常真实的客户)需要能够将这些帖子添加到购物车中.有解决方案吗
谢谢大家!

解决方法

我也处于同样的境地,并成功解决了问题.
我把它变成了一个插件.你可以在这里下载 http://reigelgallarde.me/product/woocommerce-woorei-shop-manager/.只需阅读说明的说明.

我还想要一些反馈,因为我可能会忽略一些错误的功能.

WooCommerce php 8.1 + WordPress 5.7.2

WooCommerce php 8.1 + WordPress 5.7.2

如何解决WooCommerce php 8.1 + WordPress 5.7.2

我在 wordpress 5.7.2 上使用新的 PHP 8.1 时遇到问题。一切正常,直到打开 WooCommerce 5.3.0。然后整个网站都崩溃了。

这是我收到的错误消息:

致命错误:未捕获的错误:调用未定义的函数 putenv() in /data/web/virtuals/2036/virtual/www/domains/e-biowa.cz/wp-content/plugins/woocommerce/includes/class-wc-regenerate-images-request.PHP:37 堆栈跟踪:#0 /data/web/virtuals/2036/virtual/www/domains/e-biowa.cz/wp-content/plugins/woocommerce/includes/class-wc-regenerate-images.PHP(49): WC_Regenerate_Images_Request->__construct() #1 /data/web/virtuals/2036/virtual/www/domains/e-biowa.cz/wp-includes/class-wp-hook.PHP(292): WC_Regenerate_Images::init('''') #2 /data/web/virtuals/2036/virtual/www/domains/e-biowa.cz/wp-includes/class-wp-hook.PHP(316): WP_Hook->apply_filters(NULL,Array) #3 /data/web/virtuals/2036/virtual/www/domains/e-biowa.cz/wp-includes/plugin.PHP(484): WP_Hook->do_action(Array) #4 /data/web/virtuals/2036/virtual/www/domains/e-biowa.cz/wp-settings.PHP(560): do_action(''init'') #5 /data/web/virtuals/2036/virtual/www/domains/e-biowa.cz/wp-config.php(90): require_once(''/data/web/virtu...'') #6 /data/web/virtuals/2036/virtual/www/domains/e-biowa.cz/wp-load.PHP(37): require_once(''/data/web/virtu...'') #7 /data/web/virtuals/2036/virtual/www/domains/e-biowa.cz/wp-admin/admin.PHP(34): require_once(''/data/web/virtu...'') #8 /data/web/virtuals/2036/virtual/www/domains/e-biowa.cz/wp-admin/plugins.PHP(10): require_once(''/data/web/virtu...'') #9 {main} 被抛出 /data/web/virtuals/2036/virtual/www/domains/e-biowa.cz/wp-content/plugins/woocommerce/includes/class-wc-regenerate-images-request.PHP 第 37 行

请问有谁知道,是否有兼容性问题?我没有找到任何相关信息。

关于php – Woocommerce | WordPress – WC_Cart :: set_quantity –wordpress chatbot的介绍已经告一段落,感谢您的耐心阅读,如果想了解更多关于php – Woocommerce WC_Cart->费用和WC_Cart :: get_checkout_url已弃用、php – WordPress Woocommerce – 使用update_post_meta添加产品属性、php – 将自定义帖子类型与电子商务集成(Woocommerce o others) – WORDPRESS、WooCommerce php 8.1 + WordPress 5.7.2的相关信息,请在本站寻找。

本文标签: