如果您能帮我解决这个问题,那就太好了。我在结帐页面上添加了一项基本上名为“附加附加项”的费用。
public function change_fee_price($cart){
$fee_cost = WC()->session->get( 'my_misc_fee_cost' ); // 0 default value.
WC()->cart->add_fee("Additional Add on", $fee_cost);
}
add_action( 'woocommerce_cart_calculate_fees', array($this, 'change_fee_price'), 20, 1 );
我已在结帐页面上为管理员编辑了此费用金额。
public function editable_additional_addon_fees($ci, $fee){
if(WC()->customer->get_role() == "administrator"){
if(is_cart()){
if($fee->id == "additional-add-on"){
$fee_total = WC()->cart->display_prices_including_tax() ? $fee->amount + $fee->tax : $fee->amount ;
$fee_total = WC()->session->get( 'my_misc_fee_cost' ) ? WC()->session->get( 'my_misc_fee_cost' ) : $fee_total;
$html = "$$fee_total <strong><i>(Edit on checkout page.)</i></strong>";
return $html;
}
}
if(is_checkout()){
if($fee->id == "additional-add-on"){
$fee_total = WC()->cart->display_prices_including_tax() ? $fee->amount + $fee->tax : $fee->amount ;
$fee_total = WC()->session->get( 'my_misc_fee_cost' ) ? WC()->session->get( 'my_misc_fee_cost' ) : $fee_total;
$html = "$<input type='number' id='misc_fee_charge' name='misc_fee_charge' value='".$fee_total."'>";
return $html;
}
}
return $ci;
}
add_filter( 'woocommerce_cart_totals_fee_html', array($this, 'editable_additional_addon_fees'), 10, 2);
现在,如果管理员想要将“Additional Add On”费用名称重命名为“Extra Charges for XYZ”而不是更改金额怎么办。
woocommerce_cart_totals_fee_html
帮助编辑费用金额的 html 而不是费用名称。我想为用户提供从前端在购物车上动态命名费用的选项,而不是添加静态名称。
有谁知道如何实现这一目标?
总而言之,问题很简单。如何提供从前端动态编辑费用名称的选项!