Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php WooCommerce:用户设置的自定义价格,不在购物车中理货_Php_Wordpress_Woocommerce - Fatal编程技术网

Php WooCommerce:用户设置的自定义价格,不在购物车中理货

Php WooCommerce:用户设置的自定义价格,不在购物车中理货,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,我们使用以下脚本允许用户在此页面上输入购买礼品卡的自定义价格: 问题是,在最近的WooCommerce 3.0.8更新中,购物车中的自定义价格不再完全正确 这是我驾驶室外面的地方。有人能给我指出正确的方向吗 function wpr_custom_price() { if ( !class_exists( 'woocommerce' ) && !class_exists( 'rpgc_woocommerce' ) ) return; }

我们使用以下脚本允许用户在此页面上输入购买礼品卡的自定义价格:

问题是,在最近的WooCommerce 3.0.8更新中,购物车中的自定义价格不再完全正确

这是我驾驶室外面的地方。有人能给我指出正确的方向吗

function wpr_custom_price() {
    if ( !class_exists( 'woocommerce' ) && !class_exists( 'rpgc_woocommerce' ) )
        return;

    }
    add_action('plugins_loaded ', 'wpr_custom_price', 20 );


    //  Adds the box to enter in the cost of the giftcard.
    function wpr_add_remove_field() {

        $currency_symbol = get_woocommerce_currency_symbol();
        $currency_pos = get_option( 'woocommerce_currency_pos' );

        _e('Enter Gift Card Value');
?>

<br />

<?php
switch ( $currency_pos ) {
    case 'left' :
        echo '<strong>' . $currency_symbol . '</strong> <input 
name="rpgc_price" id="rpgc_price" placeholder="' . __('0.00', 
WPR_CP_CORE_TEXT_DOMAIN ) . '" class="input-text" style="margin-bottom:5px; 
width: 100px;">';
    break;
    case 'right' :
        echo '<input name="rpgc_price" id="rpgc_price" placeholder="' . 
__('0.00', WPR_CP_CORE_TEXT_DOMAIN ) . '" class="input-text" style="margin-
bottom:5px; width: 100px;"><strong> ' . $currency_symbol . '</strong>';
    break;
    case 'left_space' :
        echo '<strong>' . $currency_symbol . ' </strong> <input 
name="rpgc_price" id="rpgc_price" placeholder="' . __('0.00', 
WPR_CP_CORE_TEXT_DOMAIN ) . '" class="input-text" style="margin-bottom:5px; 
width: 100px;">';
    break;
    case 'right_space' :
        echo '<input name="rpgc_price" id="rpgc_price" placeholder="' . 
__('0.00', WPR_CP_CORE_TEXT_DOMAIN ) . '" class="input-text" style="margin-
bottom:5px; width: 100px;"> <strong> ' . $currency_symbol . '</strong>';
    break;
}

}
add_action( 'rpgc_before_all_giftcard_fields', 'wpr_add_remove_field', 10 );


// Removes the display of the price on a gift card product
function wpr_remove_price( $price, $post ) {

$is_giftcard = get_post_meta( $post->id, '_giftcard', true );

if ( $is_giftcard == "yes" )
    $price = "";

return $price;
}
add_filter( 'woocommerce_get_price_html', 'wpr_remove_price', 10, 2 );

**//  Saves the Gift card amount on adding it to the cart
function wpr_add_cart_item($data) {
if ( isset( $_POST['rpgc_price'] ) )
    $data['Price'] = (double) woocommerce_clean( $_POST['rpgc_price'] );
return $data;
}
add_filter('rpgc_giftcard_data', 'wpr_add_cart_item', 10, 1);
//  Replaces the $0 price of the Gift card with the amount entered by the 
customer
function wpr_add_custom_price( $cart_object ) {
foreach ( $cart_object->cart_contents as $key => $value ) {
    if( isset( $value["variation"]["Price"] ) )
        $value['data']->price = $value["variation"]["Price"];
}
}
add_action( 'woocommerce_before_calculate_totals', 'wpr_add_custom_price' );
//  Updates the price in the Mini Cart
function wpr_minicart_price ( $price, $cart_item, $cart_item_key ){

$is_giftcard = get_post_meta( $cart_item [ "product_id" ], '_giftcard', true 
);
if ( $is_giftcard == "yes" ) {
    $price = woocommerce_price( $cart_item ["variation"]["Price"] );

}
return $price;
}
add_filter('woocommerce_cart_item_price','wpr_minicart_price', 10, 3);
add_filter('woocommerce_add_to_cart_validation', 
'my_custom_checkout_field_process', 10, 2);

function my_custom_checkout_field_process( $state, $product_id ) {

$is_giftcard = get_post_meta( $product_id, '_giftcard', true );
if ( $is_giftcard == "yes" ) {
    // Check if set, if its not set add an error.
    if ( ! $_POST['rpgc_price'] ) {
        wc_add_notice( __( 'Please enter a price for the gift card.' ), 
'error' );
        $state = false;
    }
}
return $state;
}**

/**
* Load the Text Domain for i18n
*
* @return void
* @access public
*/

  function rpgc_custprice_loaddomain() {
    load_plugin_textdomain( 'rpgc-customprice', false, dirname( plugin_basename( 
    __FILE__ ) ) . "/languages" );
  }
  add_action( 'init', 'rpgc_custprice_loaddomain' );
?>
函数wpr\u custom\u price(){
如果(!class_存在('woocommerce')&&!class_存在('rpgc_woocommerce'))
返回;
}
添加操作(“插件加载”、“wpr\U自定义价格”,20);
//添加要输入礼品卡成本的框。
函数wpr_add_remove_field(){
$currency\u symbol=获取\u商业\u currency\u symbol();
$currency_pos=get_选项('woocommerce_currency_pos');
_e(“输入礼品卡价值”);
?>


用以下内容替换此行
$value['data']->price=$value[“variation”][“price”];
$value['data']->set_price($value[“variation”][“price”]);
因为在新版本中,我们只能通过该对象获取产品的对象。我们可以调用
set_price()
函数来设置当前价格