Last active
August 15, 2024 15:16
-
-
Save eto4detak/ed2bcdb5a52d48fd027e1de1e698f992 to your computer and use it in GitHub Desktop.
woo php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$product = wc_get_product( $post->ID ); | |
// attribute | |
$razmer = array_shift( wc_get_product_terms( $product->id, 'pa_razmer', array( 'fields' => 'names' ) ) ); | |
$variation_ids = $product->get_children( $args = '', $output = OBJECT ); | |
foreach ($variation_ids as $key => $pv_id) { | |
$pv = new WC_Product_Variation($pv_id); | |
$pv_array[] = $pv; | |
} | |
// update price | |
function _set_woo_price($post_id, $new_price = '', $new_sale_price = '') | |
{ | |
if(!empty($new_price)){ | |
update_post_meta($post_id, '_regular_price', $new_price); | |
update_post_meta($post_id, '_price', $new_price); | |
}else{ | |
update_post_meta($post_id, '_regular_price', ''); | |
} | |
if(!empty($new_sale_price)){ | |
update_post_meta($post_id, '_sale_price', $new_sale_price); | |
update_post_meta($post_id, '_price', $new_sale_price); | |
}else{ | |
update_post_meta($post_id, '_sale_price', ''); | |
} | |
} | |
function _set_woo_sale_price($post_id, $new_sale_price = '') | |
{ | |
if(!empty($new_sale_price)){ | |
update_post_meta($post_id, '_sale_price', $new_sale_price); | |
update_post_meta($post_id, '_price', $new_sale_price); | |
}else{ | |
update_post_meta($post_id, '_sale_price', ''); | |
} | |
} | |
function _update_woo_price($post_id, $new_price = '', $new_sale_price = '') | |
{ | |
if(!empty($new_price)){ | |
update_post_meta($post_id, '_regular_price', $new_price); | |
update_post_meta($post_id, '_price', $new_price); | |
} | |
if(!empty($new_sale_price)){ | |
update_post_meta($post_id, '_sale_price', $new_sale_price); | |
update_post_meta($post_id, '_price', $new_sale_price); | |
} | |
} | |
/////////////////////////////////////////////////////////////////////////////////////////// | |
/////// HOOKS | |
/////////////////////////////////////////////////////////////////////////////////////////// | |
// empty addcart | |
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 ); | |
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 ); | |
add_action('woocommerce_single_product_summary', 'divie_init_woo_product_button',1); | |
function divie_init_woo_product_button($value='') | |
{ | |
global $product; | |
if(!empty($product) && $product->is_type( 'simple' )){ | |
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30); | |
add_action('woocommerce_single_product_summary', 'divie_wrapper_add_to_cart', 15); | |
add_action('woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 15); | |
add_action('woocommerce_single_product_summary', 'divie_add_button_ask_question', 16); | |
add_action('woocommerce_single_product_summary', 'divie_end_wrapper_add_to_cart', 17); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment