I’ve a wordpress plugin which performs a depend of bought merchandise in an order that are flagged with my customized metadata worth.
The customized metadata worth is within the type of a checkbox throughout the product web page. I am utilizing WooCommerce/WooCommerce subscriptions.
If a buyer purchases 5 merchandise, a depend is completed after which saved in a variable. Solely merchandise which have the customized metadata worth checkbox are counted.
The depend doesn’t happen, as I imagine my customized metadata worth checkbox shouldn’t be being detected when utilizing get_meta();
throughout the loop.
Code beneath exhibits the metadata checkbox
/* Including Further subject to product to Allow Traccar integration */
// Show Fields
add_action('woocommerce_product_options_general_product_data', 'wootraccar_product_custom_fields_add');
perform wootraccar_product_custom_fields_add(){
international $publish;
echo '<div class="wootraccar_product_custom_field">';
// Customized Product Checkbox Area
woocommerce_wp_checkbox( array(
'id' => '_wootraccar_integration',
'desc' => __('Verify this field if Traccar integration is required for this product', 'woocommerce'),
'label' => __('Traccar Integration Required', 'woocommerce'),
'desc_tip' => 'true'
));
echo '</div>';
}
// Save Fields
add_action('woocommerce_process_product_meta', 'wootraccar_product_custom_fields_save');
perform wootraccar_product_custom_fields_save($post_id){
// Customized Product Textual content Area
$wootraccar_integration = isset( $_POST['_wootraccar_integration'] ) ? 'sure' : 'no';
update_post_meta($post_id, '_wootraccar_integration', esc_attr( $wootraccar_integration ));
}
the for every loop
$order = wc_get_order( $order_id );
$electronic mail = $order->get_billing_email();
$identify = $order->get_billing_first_name();
$devicecount =0;
foreach ( $order->get_items() as $merchandise ) {
if( $item->get_meta( '_wootraccar_integration', true )=='sure')
{
$devicecount = $devicecount + $item->get_quantity();
}
}