gpt4 book ai didi

wordpress - 自定义产品上缺少“添加到购物车”按钮

转载 作者:行者123 更新时间:2023-12-02 00:43:28 26 4
gpt4 key购买 nike

代码:

<?php

// --- Product Type: re_subscription -- Custom Fields: type (mls / nomls), duration in days ---

// --- Actions & Filters ---

add_filter('product_type_selector', 're_add_subscription_product_type');
add_filter('woocommerce_product_data_tabs', 're_remove_shipping_menu', 10, 1);
add_filter('woocommerce_product_class', 're_subscription_product_class', 10, 2);

add_action('plugins_loaded', 're_create_subscription_product_type');
add_action('admin_footer', 're_subscription_admin_custom_js');
add_action('woocommerce_product_options_general_product_data', 're_add_custom_settings');
add_action('woocommerce_process_product_meta', 're_save_custom_settings');


// --- Create Product Type ---

function re_add_subscription_product_type($types){
$types['re_subscription'] = __('RealEstate Subscription');
return $types;
}

function re_create_subscription_product_type(){
// declare the product class
class WC_Product_Re_Subscription extends WC_Product{
public function __construct($product) {
$this->product_type = 're_subscription';
parent::__construct($product);
// add additional functions here
}

/**
* Get internal type.
* Needed for WooCommerce 3.0 Compatibility
* @return string
*/

public function get_type() {
return 're_subscription';
}
}
}

function re_subscription_product_class($classname, $product_type) {
if ($product_type == 're_subscription')
$classname = 'WC_Product_Re_Subscription';

return $classname;
}


// --- Remove Shipping Menu ---

function re_remove_shipping_menu($tabs){
/*
The available tab array keys are:
general, inventory, shipping, linked_product, attribute, variations, advanced
*/
unset($tabs['shipping']);
return $tabs;
}

// --- Show General Tab ---

function re_subscription_admin_custom_js() {
if ('product' != get_post_type()) :
return;
endif;

?>
<script type='text/javascript'>
jQuery(document).ready(function () {
// For Price tab
jQuery('.product_data_tabs .general_tab').show();
jQuery('#general_product_data .pricing').addClass('show_if_re_subscription').show();

});
</script>
<?php
}

// --- Add Fields ---

function re_add_custom_settings() {
global $woocommerce, $post;
$post_id = $post->ID;
$re_is_mls = get_post_meta($post_id, 're_is_mls', true);
if($re_is_mls == '')
$re_is_mls = 'no';

echo '<div class="options_group show_if_re_subscription">';
// Duration
woocommerce_wp_text_input(
array(
'id' => 're_duration_field',
'label' => __('Duration in days', 'woocommerce' ),
'placeholder' => '30',
'desc_tip' => 'true',
'description' => __('Duration of the subscription in days', 'woocommerce'),
'type' => 'number',
));

// Type
woocommerce_wp_checkbox(
array(
'id' => 're_is_mls',
'label' => __('Is this MLS?', 'woocommerce'),
'value' => $re_is_mls,
));

echo '</div>';
}

function re_save_custom_settings($post_id){
// Save Duration field
$re_duration_fielld = $_POST['re_duration_field'];
if(!empty($re_duration_fielld))
update_post_meta($post_id, 're_duration_field', esc_attr($re_duration_fielld));

// Save MLS option
$re_is_mls = isset($_POST['re_is_mls']) ? 'yes' : 'no';
update_post_meta($post_id, 're_is_mls', $re_is_mls);
}

截图:http://prntscr.com/hq4zzo

在简单产品上,“添加到购物车”产品按钮显示且工作正常,但在我的自定义产品上,“添加到购物车”按钮缺失。价格仍然显示得很好。

我已发布到/r/woocommerce 并没有得到答案:/希望在这里得到一些东西:3

有人知道去哪里看吗?谢谢:)

最佳答案

类似于Howdy_McGee's answer ,但调用 do_action 而不是 wc_get_template:

add_action( "woocommerce_{$my_product_type}_add_to_cart", function() {
do_action( 'woocommerce_simple_add_to_cart' );
});

关于wordpress - 自定义产品上缺少“添加到购物车”按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47910821/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com