我试图在结账时向订单总额支付定制费用.我在woocommerce中添加了一个复选框
add_action( 'woocommerce_after_checkout_billing_form', 'add_box_option_to_checkout' );
function add_box_option_to_checkout( $checkout ) {
echo '<div id="message_fields">';
woocommerce_form_field( 'add_gift_box', array(
'type' => 'checkbox',
'class' => array('add_gift_box form-row-wide'),
'label' => __('Ilo?? pude?ek ozdobnych - 25 PLN/szt'),
'placeholder' => __(''),
), $checkout->get_value( 'add_gift_box' ));
}
Run Code Online (Sandbox Code Playgroud)
包含一个可以处理事件的自定义js文件
jQuery( document ).ready(function( $ ) {
$('#add_gift_box').click(function(){
var data = {
action: 'woocommerce_add_gift_box',
state: '200',
};
jQuery.ajax({
type: 'POST',
url: wc_checkout_params.ajax_url,
data: data,
success: function (code) {
console.log(code);
jQuery('body').trigger('update_checkout');
},
dataType: 'html'
});
});
});
Run Code Online (Sandbox Code Playgroud)
和PHP费用处理功能
function woo_add_cart_fee( $data ){ …Run Code Online (Sandbox Code Playgroud) 我有一个小部件,我可以将物品放入垃圾桶.我希望能够在drop事件中为垃圾桶中丢弃的每个项目添加唯一ID.我怎么能这样做,有没有办法让输出值成为列表项的实际名称?谢谢!以下是我的代码:
$(function() {
var $gallery = $( "#gallery" ),
$trash = $( "#trash" );
$( "li", $gallery ).draggable({
cancel: "a.ui-icon",
revert: "invalid",
containment: $( "#demo-frame" ).length ? "#demo-frame" : "document", // stick to demo-frame if present
helper: "clone",
cursor: "move"
});
$trash.droppable({
accept: "#gallery > li",
activeClass: "ui-state-highlight",
drop: function( event, ui ) {
deleteImage( ui.draggable );
}
});
$gallery.droppable({
accept: "#trash li",
activeClass: "custom-state-active",
drop: function( event, ui ) {
recycleImage( ui.draggable );
}
});
Run Code Online (Sandbox Code Playgroud)
HTML
<div class="demo ui-widget …Run Code Online (Sandbox Code Playgroud)