Javascript 在Thanyou页面上嵌入带有订单数据的JS脚本
我需要创建一个脚本,在woocommerce的感谢页面上发送查询 我正试图为一个发货脚本做一些类似的事情,但我需要调用一个api,其中包含从订单感谢页面激发的地址和SKU。你们谁能帮忙Javascript 在Thanyou页面上嵌入带有订单数据的JS脚本,javascript,php,wordpress,woocommerce,orders,Javascript,Php,Wordpress,Woocommerce,Orders,我需要创建一个脚本,在woocommerce的感谢页面上发送查询 我正试图为一个发货脚本做一些类似的事情,但我需要调用一个api,其中包含从订单感谢页面激发的地址和SKU。你们谁能帮忙 window.DeliverrApi.getShippingOptions({ 目的地:{ 街道1:“萨特街110号”, 街道2:“9楼”, 邮政编码:“94014”, 城市:“旧金山”, 国家:“CA”, 国家:“美国” }, SKU:[ “sku127” ], sellerId:“交货卖方” }) 这些数据
window.DeliverrApi.getShippingOptions({
目的地:{
街道1:“萨特街110号”,
街道2:“9楼”,
邮政编码:“94014”,
城市:“旧金山”,
国家:“CA”,
国家:“美国”
},
SKU:[
“sku127”
],
sellerId:“交货卖方”
})
这些数据包括:
使用以下命令在WooCommerce Order received页面中嵌入JS for Deliver,并显示订单详细信息:
add_action( 'woocommerce_thankyou', 'deliverr_api_shipping_options_js' );
function deliverr_api_shipping_options_js( $order_id ) {
// Get the WC_Order Object instance from order id
$order = wc_get_order( $order_id );
$seller_id = 'deliverr-seller'; // ? !!! - to be defined
$skus = array(); // Initializing
// Loop through order items
foreach ( $order->get_items() as $item ) {
$product = $item->get_product(); // Get the WC_Product Object instance
$skus[] = $product->get_sku(); // Add each product sku to the array
}
?><script type="text/javascript">
jQuery( function($){
window.DeliverrApi.getShippingOptions({
destination: {
street1: "<?php echo $order->get_shipping_address_1(); ?>",
street2: "<?php echo $order->get_shipping_address_2(); ?>",
zip: "<?php echo $order->get_shipping_postcode(); ?>",
city: "<?php echo $order->get_shipping_city(); ?>",
state: "<?php echo $order->get_shipping_state(); ?>",
country: "<?php echo $order->get_shipping_country(); ?>"
}<?php if( ! empty($skus) ) { ?>,
skus: [
"<?php echo implode('", "', $skus); ?>"
]<?php }
if( ! empty($seller_id) ) { ?>,
sellerId: "deliverr-seller"
<?php } ?>
});
});
</script>
<?php
}
add_action('woocommerce_thankyou'、'deliverr_api_shipping_options_js');
函数deliverr\u api\u shipping\u options\u js($order\u id){
//从订单id获取WC_订单对象实例
$order=wc\u get\u order($order\u id);
$seller_id='deliverr seller';/?!!!-待定义
$skus=array();//正在初始化
//循环浏览订单项
foreach($order->get_items()作为$item){
$product=$item->get_product();//获取WC_产品对象实例
$sku[]=$product->get_sku();//将每个产品sku添加到阵列中
}
?>
jQuery(函数($){
window.DeliverrApi.getShippingOptions({
目的地:{
街1,
第二街:,
邮政编码:“,
城市:“,
州:“,
国家:“
},
SKU:[
“有点像这样@raunak gupta你能帮忙吗?我看到你为别人做了类似的事情。