对于页面“woocommerce_thankyou”上的 Api 需要获取 sku。我有:
$order = wc_get_order( $order_id );
foreach ($order->get_items() as $item_key => $item_values):
$product = new WC_Product($item_id);
$item_sku[] = $product->get_sku();
endforeach;
Run Code Online (Sandbox Code Playgroud)
但行不通。
我正在尝试在Google Analytics中添加有关订单的信息.但统计数据并未显示收到有关订单的信息.该网站不使用在线支付(也许原因与此有关).我用了答案
我在我的主题目录中的functions.php中添加了代码.
add_action( 'woocommerce_thankyou', 'google_analytics_integration', 20 );
function google_analytics_integration(){
?>
<script>
ga('require', 'ecommerce');
<?php
// GET the WC_Order object instance from, the Order ID
$order = wc_get_order( $order_id );
$order_key = $order->get_order_key();
$transaction_id = $order->get_transaction_id(); // Doesn't always exist
$transaction_id = $order_id; // (Or the order key or the transaction ID if it exist)
?>
ga('ecommerce:addTransaction', {
'id': '<?php echo $transaction_id; // To be checked ?>',
'affiliation': '<?php echo 'UA-130000602-1'; // replace by yours ?>',
'revenue': '<?php echo …Run Code Online (Sandbox Code Playgroud) 我正在尝试仅为ID 5555的一种产品制作单独的模板。要从其页面中删除照片并更改块结构。覆盖此文件会影响所有产品页面。
wp-content\plugins\woocommerce\templates\content-single-product.php
Run Code Online (Sandbox Code Playgroud)
逻辑解决方案是添加一个条件:如果产品单个产品页面的ID为5555,则将另一个模板用于其页面。我尝试了此选项,但是它不起作用。
/**
* Custom single product template.
*/
add_filter( 'single_template', 'get_custom_post_type_template' );
function get_custom_post_type_template($single_template) {
global $post;
if ($post->post_type == 'product') {
$single_template = dirname( __FILE__ ) . '/single-template.php';
}
return $single_template;
}
add_filter( 'template_include', 'portfolio_page_template', 99 );
function portfolio_page_template( $template ) {
if ( is_page( 'slug' ) ) {
$new_template = locate_template( array( 'single-template.php' ) );
if ( '' != $new_template ) {
return $new_template ;
}
}
return $template;
}
Run Code Online (Sandbox Code Playgroud)
或选项2:移除以下挂钩:
remove_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_images', 20 …Run Code Online (Sandbox Code Playgroud) 我正在尝试在产品注释(WooComerce 3+)中添加“电话”字段。*也适用于未注册的用户(访客)。电话号码只能由管理员在管理面板中查看。
*电话字段需要设为“ 必填 ”。
我尝试使用此代码,但这不起作用:
function true_phone_number_field( $fields ) {
$fields['phone'] = '<p class="comment-form-phone"><label for="phone">Phone</label> <input id="phone" name="phone" type="text" value="" size="30" /></p>';
}
add_filter( 'comment_form_default_fields', 'true_phone_number_field');
Run Code Online (Sandbox Code Playgroud) 我有代码将订单数据发送到外部送货服务,并在那里创建新订单。我注意到,如果您重新加载“谢谢”页面,代码将再次工作并发送相同的信息。结果:在支持服务中创建了多个相同的订单。我应该在代码中添加什么以避免这种情况发生?
add_action('woocommerce_thankyou', 'send_order_to_delivery');
function send_order_to_delivery( $order_id ){
// Get an instance of the WC_Order object
$order = wc_get_order( $order_id );
$order_data = $order->get_data();
$order_id = $order_data['id'];
// Send data
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://app.example.com/api/index.php?new_order");
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($ch);
curl_close($ch);
$decoded = (array) json_decode($result);
// Output
if( isset($decoded['result']) && $decoded['result'] == 'success' && isset($decoded['order_id']) && !empty($decoded['order_id']) ){
update_post_meta( $order_id, 'delivery_order_id', esc_attr( …Run Code Online (Sandbox Code Playgroud) 我在此代码中有一个错误(按顺序添加编辑页面可编辑的自定义计费字段):
add_filter( 'woocommerce_admin_billing_fields' , 'order_admin_custom_fields' );
function order_admin_custom_fields( $fields ) {
global $theorder;
$fields['billing_address_3'] = array(
'label' => __( 'Home', 'woocommerce' ),
'value'=> get_post_meta( $theorder->get_id(), 'Home', true ),
'show' => true,
'wrapper_class' => 'form-field-wide',
'style' => '',
);
$fields['billing_address_4'] = array(
'label' => __( 'Entrance', 'woocommerce' ),
'value'=> get_post_meta( $theorder->get_id(), 'Entrance', true ),
'show' => true,
'wrapper_class' => 'form-field-wide',
'style' => '',
);
$fields['billing_address_5'] = array(
'label' => __( 'Floor', 'woocommerce' ),
'value'=> get_post_meta( $theorder->get_id(), 'Floor', true ),
'show' => …Run Code Online (Sandbox Code Playgroud) php ×6
woocommerce ×6
wordpress ×6
orders ×2
curl ×1
javascript ×1
metadata ×1
product ×1
review ×1
templates ×1