从WooCommerce API中删除字段

发布于 2025-01-21 13:09:42 字数 1414 浏览 0 评论 0原文

我的网站与零售管理软件进行了与WooCommerce上有关产品有关的所有内容的沟通。每当进行同步时,所有存在的字段都会发送到WooCommerce,如果存在,则将现有数据覆盖现有数据。

由于我将零售管理软件中的“描述”字段用于其他目的以外的其他目的,但我手动输入SEO优化的产品描述,是否可以在同步阶段禁用“描述”和“ Short_Description”字段的写入。 ?我无法操纵零售管理软件,并且想知道是否有一个允许我这样做的功能。

在您的建议之后,没有多少产品被同步到WooCommerce。为什么:

CRITICAL Uncaught ArgumentCountError: Too few arguments to function alter_product_fields(), 1 passed in /home/u191122490/domains/hange.com/public_html/wp-includes/class-wp-hook.php on line 309 and exactly 3 expected in /home/u191122490/domains/hange.com/public_html/wp-content/themes/bazaar-child/functions.php:91
Stack trace:
#0 /home/u191122490/domains/hange.com/public_html/wp-includes/class-wp-hook.php(309): alter_product_fields(Object(WC_Product_Variable))
#1 /home/u191122490/domains/hange.com/public_html/wp-includes/plugin.php(189): WP_Hook->apply_filters(Object(WC_Product_Variable), Array)
#2 /home/u191122490/domains/hange.com/public_html/wp-content/plugins/woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-products-controller.php(724): apply_filters('woocommerce_res...', Object(WC_Product_Variable), Object(WP_REST_Request), true)
#3 /home/u191122490/domains/hange.com/public_html/wp-content/plugins/woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-crud-con in /home/u191122490/domains/hange.com/public_html/wp-content/themes/bazaar-child/functions.php alla riga 91

My website communicates with retail management software for everything related to products on WooCommerce. Whenever synchronisation takes place, all fields present are sent to WooCommerce overwriting existing data if present.

Since I use the "Description" field within the retail management software for other purposes than WooCommerce where I manually enter SEO-optimised product descriptions, is there a way to disable the writing of the "description" and "short_description" fields during the synchronisation phase? I have no way to manipulate the retail management software and was wondering if there was a function that would allow me to do this.

After your suggestion, no many products were synced to WooCommerce. Here's why:

CRITICAL Uncaught ArgumentCountError: Too few arguments to function alter_product_fields(), 1 passed in /home/u191122490/domains/hange.com/public_html/wp-includes/class-wp-hook.php on line 309 and exactly 3 expected in /home/u191122490/domains/hange.com/public_html/wp-content/themes/bazaar-child/functions.php:91
Stack trace:
#0 /home/u191122490/domains/hange.com/public_html/wp-includes/class-wp-hook.php(309): alter_product_fields(Object(WC_Product_Variable))
#1 /home/u191122490/domains/hange.com/public_html/wp-includes/plugin.php(189): WP_Hook->apply_filters(Object(WC_Product_Variable), Array)
#2 /home/u191122490/domains/hange.com/public_html/wp-content/plugins/woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-products-controller.php(724): apply_filters('woocommerce_res...', Object(WC_Product_Variable), Object(WP_REST_Request), true)
#3 /home/u191122490/domains/hange.com/public_html/wp-content/plugins/woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-crud-con in /home/u191122490/domains/hange.com/public_html/wp-content/themes/bazaar-child/functions.php alla riga 91

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情感失落者 2025-01-28 13:09:42

挂钩woocommerce_rest_pre_insert _ {$ this-> post_type} _Object可用于更改,然后通过WC REST API插入/更新邮政类型。 $ this-post_type可以是'product',shop_order','shop_coupon'...等。

/**
* Filters an object before it is inserted via the REST API.
*
* The dynamic portion of the hook name, `$this->post_type`,
* refers to the object type slug.
*
* @param WC_Data         $product  Object object.
* @param WP_REST_Request $request  Request object.
* @param bool            $creating If is creating a new object.
*/
return apply_filters( "woocommerce_rest_pre_insert_{$this->post_type}_object", $product, $request, $creating );

$创建对象决定它是更新还是插入调用。

add_filter('woocommerce_rest_pre_insert_product_object', 'alter_product_fields', 10, 3);


function alter_product_fields($product, $request, $creating) {

// $creating -- True If is creating a new object. False is update request

if(!$creating){
    $existing_product_details = wc_get_product($product->get_id());
    $product->set_description($existing_product_details->get_description());
    $product->set_short_description($existing_product_details->get_short_description());

    return $product;
}

The hook woocommerce_rest_pre_insert_{$this->post_type}_object can be used for altering before inserting/updating a post type through WC Rest API. The $this->post_type can be 'product', 'shop_order', 'shop_coupon'...etc.

/**
* Filters an object before it is inserted via the REST API.
*
* The dynamic portion of the hook name, `$this->post_type`,
* refers to the object type slug.
*
* @param WC_Data         $product  Object object.
* @param WP_REST_Request $request  Request object.
* @param bool            $creating If is creating a new object.
*/
return apply_filters( "woocommerce_rest_pre_insert_{$this->post_type}_object", $product, $request, $creating );

This $creating object decides whether it is an update or insert call.

add_filter('woocommerce_rest_pre_insert_product_object', 'alter_product_fields', 10, 3);


function alter_product_fields($product, $request, $creating) {

// $creating -- True If is creating a new object. False is update request

if(!$creating){
    $existing_product_details = wc_get_product($product->get_id());
    $product->set_description($existing_product_details->get_description());
    $product->set_short_description($existing_product_details->get_short_description());

    return $product;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文