我一直在努力寻找如何实现这一点。我想隐藏主商店页面上一个(或多个)类别的产品,但不隐藏它们在各自的类别页面中。我找到了隐藏类别的解决方案,但它总是使它们在类别页面上不可见……我不想要。
原因是这个特定的类别有数千种产品,我不希望这些产品淹没并隐藏其他更加多样化的产品。
我一直在努力寻找如何实现这一点。我想隐藏主商店页面上一个(或多个)类别的产品,但不隐藏它们在各自的类别页面中。我找到了隐藏类别的解决方案,但它总是使它们在类别页面上不可见……我不想要。
原因是这个特定的类别有数千种产品,我不希望这些产品淹没并隐藏其他更加多样化的产品。
我正在尝试创建一个 cron 作业,它将比较设置为产品元数据的日期与当前日期,然后在设置为产品元数据的日期已过时更新产品库存。
这是我到目前为止所拥有的,但它不起作用:
// Custom CRON Function
function update_pre_order_stock_status($post_id){
$current_date = date( 'YYYY-mm-dd' );
$expiryDate = $product->get_meta('woo_expiry_date');
$woo_expiry_action = $product->get_meta('woo_expiry_action');
$product_category = array( 'comic-book-pre-orders', 'dc-comics-pre-orders', 'image-comics-pre-orders', 'manga-pre-orders', 'marvel-comics-pre-orders', 'other-publisher-pre-orders');
if(( is_product_category( $product_category )) && ( $expiryDate <= $current_date ) && ( $woo_expiry_action == 'out' )) {
// 1. Updating the stock quantity
update_post_meta( $post_id, '_stock', 0);
// 2. Updating the stock quantity
update_post_meta( $post_id, '_stock_status', wc_clean( 'outofstock' ) );
// 3. Updating post term relationship
wp_set_post_terms( $post_id, 'outofstock', 'product_visibility', true );
}
}
if ( ! wp_next_scheduled( 'my_pre_order_stock_update' ) ) {
wp_schedule_event( time(), 'hourly', 'my_pre_order_stock_update' );
}
add_action( 'my_pre_order_stock_update', 'update_pre_order_stock_status' );
Cron 事件“my_pre_order_stock_update”显示在 cron 列表中,但运行它没有执行任何操作。
任何建议将非常感激!
在 WooCommerce 中,我定义了添加/定义了一些产品属性及其名称,并且编写了一些代码,允许我在可变产品级别定义替代属性标签名称。
因此,例如,在单个产品页面中,对于某些产品,属性“颜色”可以显示为“T 恤颜色”,而在其他一些产品上,属性“颜色”可以显示为“帽子颜色”。这样,我可以灵活地对不同类型的项目使用相同的属性,但在前端显示不同的属性标签名称。
// Create text input where text for custom label will be entered
add_action('woocommerce_product_options_attributes', 'add_custom_attribute_label_fields');
function add_custom_attribute_label_fields() {
global $post;
// Get the product attributes
$product_attributes = maybe_unserialize(get_post_meta($post->ID, '_product_attributes', true));
if (!empty($product_attributes)) {
echo '<div class="options_group">';
foreach ($product_attributes as $attribute_name => $attribute) {
if ($attribute['is_taxonomy']) {
$field_id = 'custom_attribute_label_' . $attribute_name;
$label = get_post_meta($post->ID, $field_id, true);
woocommerce_wp_text_input(array(
'id' => $field_id,
'label' => 'Name of the ATTRIBUTE ' . esc_html(wc_attribute_label($attribute["name"])) . ' for that product.',
'description' => esc_html('Please enter the name of that You would like to e shown at the single product page.'),
'desc_tip' => true,
'value' => esc_attr($label),
));
}
}
echo '</div>';
}
}
// Save the custom attribute labels
add_action('woocommerce_admin_process_product_object', 'save_custom_attribute_labels');
function save_custom_attribute_labels($product) {
$product_id = $product->get_id();
// Get the product attributes
$product_attributes = maybe_unserialize(get_post_meta($product_id, '_product_attributes', true));
if (!empty($product_attributes)) {
foreach ($product_attributes as $attribute_name => $attribute) {
if ($attribute['is_taxonomy']) {
$field_id = 'custom_attribute_label_' . $attribute_name;
if (isset($_POST[$field_id])) {
update_post_meta($product_id, $field_id, sanitize_text_field($_POST[$field_id]));
}
}
}
}
}
// Filter to display custom attribute label
add_filter('woocommerce_attribute_label', 'custom_attribute_label', 100, 3);
function custom_attribute_label($label, $name, $attproduct) {
// Ensure $attproduct is an instance of WC_Product
if (is_a($attproduct, 'WC_Product')) {
$product_id = $attproduct->get_id();
// Retrieve the custom label
$custom_label = get_post_meta($product_id, 'custom_attribute_label_' . $name, true);
// Check if custom label is not empty and return it
if (!empty($custom_label)) {
return $custom_label;
}
}
}
但我无法让它工作。如果我在函数“自定义属性标签”中插入一些“回声”,那么我就可以在变体表单中看到保存的替代属性标签,并重复与该产品的变体数量相同的次数。但产品属性标签名称仍为旧名称。
我正在我的 WooCommerce 商店和第三方工具之间同步订单,并且我正在使用 REST API 重新制作同步程序。我想要获得一批新订单,在将它们插入数据库后,我想设置一个状态或标志,以便下次我请求一批订单时,我不会得到相同的订单。
里面详细介绍了如何获得订单,而且确实有效。我不想使用 STATUS 字段,因为商店经理可以更改它。我不想排除订单 ID 列表,因为随着时间的推移它会变得太长。寻找一个字段,我可以使用该字段将返回的订单限制为我尚未看到的订单,并且能够在成功同步后更新该字段。看起来可能吗?
是一个已经存在的领域还是一种创建该领域的方法?
我想知道是否有一个字段将订单标记为之前已同步,以便我可以仅请求尚未同步的新订单。这似乎是一件常见的事情,希望有人做过并提供建议。